Example #1
0
  public static boolean maybeSameLocation(Value v1, Value v2) {
    if (!(v1 instanceof InstanceFieldRef && v2 instanceof InstanceFieldRef)
        && !(v1 instanceof ArrayRef && v2 instanceof ArrayRef)) {
      return v1.equivTo(v2);
    }
    if (v1 instanceof InstanceFieldRef && v2 instanceof InstanceFieldRef) {
      InstanceFieldRef ifr1 = (InstanceFieldRef) v1;
      InstanceFieldRef ifr2 = (InstanceFieldRef) v2;
      if (!ifr1.getField().getName().equals(ifr2.getField().getName())) return false;

      Local base1 = (Local) ifr1.getBase();
      Local base2 = (Local) ifr2.getBase();
      PointsToAnalysis pta = Scene.v().getPointsToAnalysis();
      PointsToSet pts1 = pta.reachingObjects(base1);
      PointsToSet pts2 = pta.reachingObjects(base2);
      return pts1.hasNonEmptyIntersection(pts2);
    } else { // v1 instanceof ArrayRef && v2 instanceof ArrayRef
      ArrayRef ar1 = (ArrayRef) v1;
      ArrayRef ar2 = (ArrayRef) v2;

      Local base1 = (Local) ar1.getBase();
      Local base2 = (Local) ar2.getBase();
      PointsToAnalysis pta = Scene.v().getPointsToAnalysis();
      PointsToSet pts1 = pta.reachingObjects(base1);
      PointsToSet pts2 = pta.reachingObjects(base2);
      return pts1.hasNonEmptyIntersection(pts2);
    }
  }
Example #2
0
 private static SootClass makeFreshClass(String name) {
   // reset the testClass
   if (Scene.v().containsClass(name)) {
     Scene.v().removeClass(Scene.v().getSootClass(name));
   }
   SootClass result = new SootClass(name);
   Scene.v().addClass(result);
   return result;
 }
Example #3
0
 public static void restart() {
   dispose();
   for (Scene scene : new ArrayList<Scene>(scenes)) {
     scenes.remove(scene);
     scene.end();
   }
   if (profiler.scene != null) profiler.scene.end();
   init();
   scenes.add(firstScene);
 }
Example #4
0
  /**
   * @ast method
   * @aspect Expressions
   * @declaredat
   *     /Users/eric/Documents/workspaces/clara-soot/JastAddExtensions/JimpleBackend/Expressions.jrag:84
   */
  public soot.Value eval(Body b) {
    TypeDecl dest = getDest().type();
    TypeDecl source = getSource().type();
    if (dest.isString()) {

      Value lvalue = getDest().eval(b);

      Value v = asImmediate(b, lvalue);

      // new StringBuffer(left)
      Local local =
          b.newTemp(b.newNewExpr(lookupType("java.lang", "StringBuffer").sootRef(), this));
      b.setLine(this);
      b.add(
          b.newInvokeStmt(
              b.newSpecialInvokeExpr(
                  local,
                  Scene.v()
                      .getMethod("<java.lang.StringBuffer: void <init>(java.lang.String)>")
                      .makeRef(),
                  v,
                  this),
              this));

      // append right
      Local rightResult =
          b.newTemp(
              b.newVirtualInvokeExpr(
                  local,
                  lookupType("java.lang", "StringBuffer")
                      .methodWithArgs("append", new TypeDecl[] {source.stringPromotion()})
                      .sootRef(),
                  asImmediate(b, getSource().eval(b)),
                  this));

      // toString
      Local result =
          b.newTemp(
              b.newVirtualInvokeExpr(
                  rightResult,
                  Scene.v()
                      .getMethod("<java.lang.StringBuffer: java.lang.String toString()>")
                      .makeRef(),
                  this));

      Value v2 = lvalue instanceof Local ? lvalue : (Value) lvalue.clone();
      getDest().emitStore(b, v2, result, this);
      return result;
    } else {
      return super.eval(b);
    }
  }
Example #5
0
 public Map<Unit, Set<TaintFact>> initialSeeds() {
   if (DEBUG) System.out.println("initial seeds");
   return DefaultSeeds.make(
       Collections.singleton(
           Scene.v().getEntryPoints().get(0).getActiveBody().getUnits().getFirst()),
       zeroValue());
 }
public class TopologicalOrderer {
  CallGraph cg;
  List<SootMethod> order = new ArrayList<SootMethod>();
  NumberedSet visited = new NumberedSet(Scene.v().getMethodNumberer());

  public TopologicalOrderer(CallGraph cg) {
    this.cg = cg;
  }

  public void go() {
    Iterator methods = cg.sourceMethods();
    while (methods.hasNext()) {
      SootMethod m = (SootMethod) methods.next();
      dfsVisit(m);
    }
  }

  private void dfsVisit(SootMethod m) {
    if (visited.contains(m)) return;
    visited.add(m);
    Iterator targets = new Targets(cg.edgesOutOf(m));
    while (targets.hasNext()) {
      SootMethod target = (SootMethod) targets.next();
      dfsVisit(target);
    }
    order.add(m);
  }

  public List<SootMethod> order() {
    return order;
  }
}
Example #7
0
 public OnFlyCallGraph(PAG pag) {
   this.pag = pag;
   CGOptions options = new CGOptions(PhaseOptions.v().getPhaseOptions("cg"));
   if (options.all_reachable()) {
     List entryPoints = new ArrayList();
     entryPoints.addAll(EntryPoints.v().all());
     entryPoints.addAll(EntryPoints.v().methodsOfApplicationClasses());
     Scene.v().setEntryPoints(entryPoints);
   }
   callGraph = new CallGraph();
   Scene.v().setCallGraph(callGraph);
   ContextManager cm = CallGraphBuilder.makeContextManager(callGraph);
   reachableMethods = Scene.v().getReachableMethods();
   ofcgb = new OnFlyCallGraphBuilder(cm, reachableMethods);
   reachablesReader = reachableMethods.listener();
   callEdges = cm.callGraph().listener();
 }
  public static void main(String args[]) {
    // Set classPath
    String exemplePath = "/Users/gamyot/Documents/workspace/Soot_Exemples/src/";
    String objectPath = "/System/Library/Frameworks/JavaVM.framework/Classes/classes.jar";
    String tracePath = "/Users/gamyot/Documents/workspace/SootInstrumenter/src/";

    Scene.v().setSootClassPath(".:" + objectPath + ":" + exemplePath + ":" + tracePath);

    Scene.v().loadClassAndSupport("java.lang.Object");
    Scene.v().loadClassAndSupport("java.lang.System");

    // Set up the class we’re working with
    SootClass c = Scene.v().loadClassAndSupport("MyExemples.ExempleBasic");
    c.setApplicationClass();

    // Get methods
    Iterator<SootMethod> methodIterator = c.methodIterator();
    while (methodIterator.hasNext()) methodList.add(methodIterator.next());
    // Iterate through the method list
    for (SootMethod m : methodList) {
      Body body = m.retrieveActiveBody();
      PatchingChain<Unit> unitList = body.getUnits();
      // get the all the "if statements" Units
      List<Unit> ifStmtList = searchIfStmts(body);

      // for each "if statement" unit, instrument and add the instrumentation code right after
      for (Unit ifStmtUnit : ifStmtList) {
        // Chain<Unit> instrumentedChain = generateInstrumentationUnits(ifStmtUnit, body);
        // unitList.insertAfter(instrumentedChain, ifStmtUnit);
        Chain<Unit> testChain = generateInstrumentationUnits(ifStmtUnit, body);
        unitList.insertAfter(testChain, ifStmtUnit);
      }
      // Output all the units for this method on terminal
      String methodName = m.getName();
      System.out.println(
          "____Method: \"" + methodName + "\"__________________________________________________");
      LoadAndGenerate.printAllUnits(body);
    }

    try {
      LoadAndGenerate.outputClassToBinary(c);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Example #9
0
  /**
   * Indicates whether this ThrowableSet includes some exception that might be caught by a handler
   * argument of the type <code>catcher</code>.
   *
   * @param catcher type of the handler parameter to be tested.
   * @return <code>true</code> if this set contains an exception type that might be caught by <code>
   *     catcher</code>, false if it does not.
   */
  public boolean catchableAs(RefType catcher) {
    if (INSTRUMENTING) {
      Manager.v().catchableAsQueries++;
    }

    FastHierarchy h = Scene.v().getOrMakeFastHierarchy();

    if (exceptionsExcluded.size() > 0) {
      if (INSTRUMENTING) {
        Manager.v().catchableAsFromSearch++;
      }
      for (Iterator i = exceptionsExcluded.iterator(); i.hasNext(); ) {
        AnySubType exclusion = (AnySubType) i.next();
        if (h.canStoreType(catcher, exclusion.getBase())) {
          return false;
        }
      }
    }

    if (exceptionsIncluded.contains(catcher)) {
      if (INSTRUMENTING) {
        if (exceptionsExcluded.size() == 0) {
          Manager.v().catchableAsFromMap++;
        } else {
          Manager.v().catchableAsFromSearch++;
        }
      }
      return true;
    } else {
      if (INSTRUMENTING) {
        if (exceptionsExcluded.size() == 0) {
          Manager.v().catchableAsFromSearch++;
        }
      }
      for (Iterator i = exceptionsIncluded.iterator(); i.hasNext(); ) {
        RefLikeType thrownType = (RefLikeType) i.next();
        if (thrownType instanceof RefType) {
          if (thrownType == catcher) {
            // assertion failure.
            throw new IllegalStateException(
                "ThrowableSet.catchableAs(RefType): exceptions.contains() failed to match contained RefType "
                    + catcher);
          } else if (h.canStoreType(thrownType, catcher)) {
            return true;
          }
        } else {
          RefType thrownBase = ((AnySubType) thrownType).getBase();
          // At runtime, thrownType might be instantiated by any
          // of thrownBase's subtypes, so:
          if (h.canStoreType(thrownBase, catcher) || h.canStoreType(catcher, thrownBase)) {
            return true;
          }
        }
      }
      return false;
    }
  }
Example #10
0
  public static void resize(int width, int height) {
    spriteBatch.getProjectionMatrix().setToOrtho2D(0, 0, width, height);

    if (frameBuffer != null) frameBuffer.dispose();
    if (tempBuffer != null) tempBuffer.dispose();

    frameBuffer =
        new RenderBuffer(
            spriteBatch); // Have to recreate all render buffers and adjust the projection matrix as
                          // the window size has changed
    tempBuffer = new RenderBuffer(spriteBatch);
    for (Scene scene : scenes) {

      if (scene.lastFrameBuffer != null) scene.lastFrameBuffer.dispose();

      scene.lastFrameBuffer = new RenderBuffer(null);
    }
  }
Example #11
0
  /** Display a dialog which allows the user to export a scene to an OBJ file. */
  public static void exportFile(BFrame parent, Scene theScene) {
    // Display a dialog box with options on how to export the scene.

    // ValueField errorField = new ValueField(0.05, ValueField.POSITIVE);
    // final ValueField widthField = new ValueField(200.0, ValueField.INTEGER+ValueField.POSITIVE);
    // final ValueField heightField = new ValueField(200.0, ValueField.INTEGER+ValueField.POSITIVE);
    // final ValueSlider qualitySlider = new ValueSlider(0.0, 1.0, 100, 0.5);
    // final BCheckBox smoothBox = new BCheckBox(Translate.text("subdivideSmoothMeshes"), true);
    final BCheckBox injectChoice = new BCheckBox(Translate.text("Inject"), true);
    // final BCheckBox UVChoice = new BCheckBox(Translate.text("Export UV"), true);

    /*BComboBox exportChoice = new BComboBox(new String [] {
      Translate.text("exportWholeScene"),
      Translate.text("selectedObjectsOnly")
    });*/

    ComponentsDialog dlg;
    if (theScene.getSelection().length > 0)
      dlg =
          new ComponentsDialog(
              parent,
              Translate.text("InjectToM2"),
              new Widget[] {injectChoice},
              new String[] {null, null, null, null, null});
    else
      dlg =
          new ComponentsDialog(
              parent,
              Translate.text("exportToM2"),
              new Widget[] {injectChoice},
              new String[] {null, null, null, null});
    if (!dlg.clickedOk()) return;

    // Ask the user to select the output file.

    BFileChooser fc = new BFileChooser(BFileChooser.SAVE_FILE, Translate.text("exportToWMO"));
    fc.setSelectedFile(new File("Untitled.m2"));
    if (ArtOfIllusion.getCurrentDirectory() != null)
      fc.setDirectory(new File(ArtOfIllusion.getCurrentDirectory()));
    if (!fc.showDialog(parent)) return;
    File dir = fc.getDirectory();
    f = fc.getSelectedFile();
    String name = f.getName();
    String baseName = (name.endsWith(".m2") ? name.substring(0, name.length() - 3) : name);
    ArtOfIllusion.setCurrentDirectory(dir.getAbsolutePath());

    m2 obj = null;
    try {
      obj = new m2(fileLoader.openBuffer(f.getAbsolutePath()));
    } catch (InvalidClassException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    writeScene(theScene, obj, false, 0.05, false, injectChoice.getState());
  }
Example #12
0
  /**
   * Update local information from the scene. It's important that this method is synchronized
   * because we get ConcurrentModificationException's during rendering otherwise.
   *
   * <p>This method is called from sceneChanged().
   */
  protected synchronized void updateCharges(Scene theScene) {
    // Clear cached infos.
    cachedBounds = null;
    cachedWire = null;
    charges.clear();

    setPositive = null;
    setNegative = null;

    // Get all selection sets.
    Object layersObj = theScene.getMetadata("selectionsPlugin.selectionSets");

    if (layersObj == null) return;

    if (!(layersObj instanceof ArrayList)) return;

    ArrayList<ObjectSet> layers = (ArrayList<ObjectSet>) layersObj;

    // Try to find those which are of interest for us.
    for (ObjectSet set : layers) {
      if (set.getName().equals(setNamePositive)) {
        setPositive = set;
      } else if (set.getName().equals(setNameNegative)) {
        setNegative = set;
      }
    }

    // Create charges.
    if (setPositive != null) {
      for (ObjectInfo oi : setPositive.getObjects(theScene)) {
        if (oi.getObject() instanceof Sphere) {
          Sphere s = (Sphere) oi.getObject();
          double q = s.getRadii().x;
          Vec3 pos = oi.getCoords().getOrigin();

          charges.add(new SphereCharge(pos, q));
        }
      }
    }

    if (setNegative != null) {
      for (ObjectInfo oi : setNegative.getObjects(theScene)) {
        if (oi.getObject() instanceof Sphere) {
          Sphere s = (Sphere) oi.getObject();
          double q = -s.getRadii().x;
          Vec3 pos = oi.getCoords().getOrigin();

          charges.add(new SphereCharge(pos, q));
        }
      }
    }
  }
  private void iterateAllMethods() {

    // Find methods
    Iterator<SootClass> getClassesIt = Scene.v().getApplicationClasses().iterator();
    while (getClassesIt.hasNext()) {
      SootClass appClass = getClassesIt.next();
      Iterator<SootMethod> getMethodsIt = appClass.getMethods().iterator();
      while (getMethodsIt.hasNext()) {
        SootMethod method = getMethodsIt.next();
        analyzeMethod(method);
      }
    }
  }
Example #14
0
  public void outAFieldSignature(AFieldSignature node) {
    String className, fieldName;
    Type t;

    fieldName = (String) mProductions.removeLast();
    t = (Type) mProductions.removeLast();
    className = (String) mProductions.removeLast();

    SootClass cl = mResolver.makeClassRef(className);
    SootFieldRef field = Scene.v().makeFieldRef(cl, fieldName, t, false);

    mProductions.addLast(field);
  }
Example #15
0
  /*
    method_signature =
    cmplt [class_name]:class_name [first]:colon type [method_name]:name  l_paren parameter_list? r_paren cmpgt;
  */
  public void outAMethodSignature(AMethodSignature node) {
    String className, methodName;
    List parameterList = new ArrayList();
    Type returnType;

    if (node.getParameterList() != null) parameterList = (List) mProductions.removeLast();

    methodName = (String) mProductions.removeLast();
    Type type = (Type) mProductions.removeLast();
    className = (String) mProductions.removeLast();

    SootClass sootClass = mResolver.makeClassRef(className);
    SootMethodRef sootMethod =
        Scene.v().makeMethodRef(sootClass, methodName, parameterList, type, false);

    mProductions.addLast(sootMethod);
  }
Example #16
0
  public void internalTransform(String phaseName, Map opts) {

    Iterator it = Scene.v().getApplicationClasses().iterator();
    while (it.hasNext()) {
      SootClass sc = (SootClass) it.next();
      // make map of first line to each method
      HashMap<Integer, SootMethod> lineToMeth = new HashMap<Integer, SootMethod>();
      Iterator methIt = sc.getMethods().iterator();
      while (methIt.hasNext()) {
        SootMethod meth = (SootMethod) methIt.next();
        if (!meth.isConcrete()) continue;
        Body body = meth.retrieveActiveBody();
        Stmt s = (Stmt) body.getUnits().getFirst();
        while (s instanceof IdentityStmt) {
          s = (Stmt) body.getUnits().getSuccOf(s);
        }
        if (s.hasTag("LineNumberTag")) {
          LineNumberTag tag = (LineNumberTag) s.getTag("LineNumberTag");
          lineToMeth.put(new Integer(tag.getLineNumber()), meth);
        }
      }
      Iterator methIt2 = sc.getMethods().iterator();
      while (methIt2.hasNext()) {
        SootMethod meth = (SootMethod) methIt2.next();
        if (!meth.isConcrete()) continue;
        Body body = meth.retrieveActiveBody();
        Stmt s = (Stmt) body.getUnits().getFirst();
        while (s instanceof IdentityStmt) {
          s = (Stmt) body.getUnits().getSuccOf(s);
        }
        if (s.hasTag("LineNumberTag")) {
          LineNumberTag tag = (LineNumberTag) s.getTag("LineNumberTag");
          int line_num = tag.getLineNumber() - 1;
          // already taken
          if (lineToMeth.containsKey(new Integer(line_num))) {
            meth.addTag(new LineNumberTag(line_num + 1));
          }
          // still available - so use it for this meth
          else {
            meth.addTag(new LineNumberTag(line_num));
          }
        }
      }
    }
  }
Example #17
0
  public void outAStaticInvokeExpr(AStaticInvokeExpr node) {
    List args;

    if (node.getArgList() != null) args = (List) mProductions.removeLast();
    else args = new ArrayList();

    SootMethodRef method = (SootMethodRef) mProductions.removeLast();
    method =
        Scene.v()
            .makeMethodRef(
                method.declaringClass(),
                method.name(),
                method.parameterTypes(),
                method.returnType(),
                true);

    mProductions.addLast(Jimple.v().newStaticInvokeExpr(method, args));
  }
Example #18
0
  /** OBJ aus Scanner laden */
  public OBJTriMesh3D(SceneReader in, List<Material> mats) throws Exception {
    String[] tokens = null;
    while ((tokens = in.getNextTokens()) != null) {
      switch (tokens.length) {
          // Ende?
        case 1:
          if (tokens[0].equals("end")) {
            if (!doLoad()) throw new Exception();
            dump();
            return;
          }
          break;

        case 2:
          if (tokens[0].equals("file")) infile = in.getRelativePath(tokens[1]);
          if (tokens[0].equals("smooth")) smooth = (new Integer(tokens[1]) == 1);

          if (tokens[0].equals("mat")) {
            mat = Scene.getLoadedMaterial(tokens[1], mats);
            if (mat == null) {
              System.err.println("Fehler, Material " + tokens[1] + " nicht gefunden.");
              throw new Exception();
            }
          }

          break;

        case 4:
          if (tokens[0].equals("origin"))
            origin = new Vec3(new Double(tokens[1]), new Double(tokens[2]), new Double(tokens[3]));
          break;
      }
    }

    // Unerwartetes Ende
    System.err.println("Fehler, unerwartetes Ende in OBJTriMesh3D-Definition.");
    throw new Exception();
  }
Example #19
0
  protected void internalTransform(String phaseName, Map options) {
    if (Options.v().verbose())
      G.v().out.println("Transforming all classes in the Scene to Shimple...");

    // *** FIXME: Add debug output to indicate which class/method is being shimplified.
    // *** FIXME: Is ShimpleTransformer the right solution?  The call graph may deem
    //            some classes unreachable.

    Iterator classesIt = Scene.v().getClasses().iterator();
    while (classesIt.hasNext()) {
      SootClass sClass = (SootClass) classesIt.next();
      if (sClass.isPhantom()) continue;

      Iterator methodsIt = sClass.getMethods().iterator();
      while (methodsIt.hasNext()) {
        SootMethod method = (SootMethod) methodsIt.next();
        if (!method.isConcrete()) continue;

        if (method.hasActiveBody()) {
          Body body = method.getActiveBody();
          ShimpleBody sBody = null;

          if (body instanceof ShimpleBody) {
            sBody = (ShimpleBody) body;
            if (!sBody.isSSA()) sBody.rebuild();
          } else {
            sBody = Shimple.v().newBody(body);
          }

          method.setActiveBody(sBody);
        } else {
          MethodSource ms = new ShimpleMethodSource(method.getSource());
          method.setSource(ms);
        }
      }
    }
  }
Example #20
0
  /**
   * Returns a <code>ThrowableSet</code> which contains all the exceptions in <code>addedExceptions
   * </code> in addition to those in this <code>ThrowableSet</code>.
   *
   * @param addedExceptions a set of {@link RefLikeType} and {@link AnySubType} objects to be added
   *     to the types included in this <code>ThrowableSet</code>.
   * @return a set containing all the <code>addedExceptions</code> as well as the exceptions in this
   *     set.
   */
  private ThrowableSet add(Set addedExceptions) {
    Set resultSet = new HashSet(this.exceptionsIncluded);
    int changes = 0;
    FastHierarchy hierarchy = Scene.v().getOrMakeFastHierarchy();

    // This algorithm is O(n m), where n and m are the sizes of the
    // two sets, so hope that the sets are small.

    for (Iterator i = addedExceptions.iterator(); i.hasNext(); ) {
      RefLikeType newType = (RefLikeType) i.next();
      if (!resultSet.contains(newType)) {
        boolean addNewType = true;
        if (newType instanceof RefType) {
          for (Iterator j = resultSet.iterator(); j.hasNext(); ) {
            RefLikeType incumbentType = (RefLikeType) j.next();
            if (incumbentType instanceof RefType) {
              if (newType == incumbentType) {
                // assertion failure.
                throw new IllegalStateException(
                    "ThrowableSet.add(Set): resultSet.contains() failed to screen duplicate RefType "
                        + newType);
              }
            } else if (incumbentType instanceof AnySubType) {
              RefType incumbentBase = ((AnySubType) incumbentType).getBase();
              if (hierarchy.canStoreType(newType, incumbentBase)) {
                // No need to add this class.
                addNewType = false;
              }
            } else { // assertion failure.
              throw new IllegalStateException(
                  "ThrowableSet.add(Set): incumbent Set element "
                      + incumbentType
                      + " is neither a RefType nor an AnySubType.");
            }
          }
        } else if (newType instanceof AnySubType) {
          RefType newBase = ((AnySubType) newType).getBase();
          for (Iterator j = resultSet.iterator(); j.hasNext(); ) {
            RefLikeType incumbentType = (RefLikeType) j.next();
            if (incumbentType instanceof RefType) {
              RefType incumbentBase = (RefType) incumbentType;
              if (hierarchy.canStoreType(incumbentBase, newBase)) {
                j.remove();
                changes++;
              }
            } else if (incumbentType instanceof AnySubType) {
              RefType incumbentBase = ((AnySubType) incumbentType).getBase();
              if (newBase == incumbentBase) {
                // assertion failure.
                throw new IllegalStateException(
                    "ThrowableSet.add(Set): resultSet.contains() failed to screen duplicate AnySubType "
                        + newBase);
              } else if (hierarchy.canStoreType(incumbentBase, newBase)) {
                j.remove();
                changes++;
              } else if (hierarchy.canStoreType(newBase, incumbentBase)) {
                // No need to add this class.
                addNewType = false;
              }
            } else { // assertion failure.
              throw new IllegalStateException(
                  "ThrowableSet.add(Set): old Set element "
                      + incumbentType
                      + " is neither a RefType nor an AnySubType.");
            }
          }
        } else { // assertion failure.
          throw new IllegalArgumentException(
              "ThrowableSet.add(Set): new Set element "
                  + newType
                  + " is neither a RefType nor an AnySubType.");
        }
        if (addNewType) {
          changes++;
          resultSet.add(newType);
        }
      }
    }

    ThrowableSet result = null;
    if (changes > 0) {
      result = Manager.v().registerSetIfNew(resultSet, this.exceptionsExcluded);
    } else {
      result = this;
    }
    return result;
  }
Example #21
0
  /**
   * Returns a <code>ThrowableSet</code> which contains <code>e</code> and all of its subclasses as
   * well as the exceptions in this set.
   *
   * <p><code>e</code> should be an instance of {@link AnySubType} if you know that the compile-time
   * type of the exception you are representing is <code>e</code>, but the exception may be
   * instantiated at run-time by a subclass of <code>e</code>.
   *
   * <p>For example, if you were recording the type of the exception thrown by
   *
   * <pre>
   * catch (IOException e) {
   *    throw e;
   * }
   * </pre>
   *
   * you would call
   *
   * <pre>
   * <code>add(AnySubtype.v(Scene.v().getRefType("java.lang.Exception.IOException")))</code>
   * </pre>
   *
   * since the handler might rethrow any subclass of <code>IOException</code>.
   *
   * @param e represents a subtree of the exception class hierarchy to add to this set.
   * @return a set containing <code>e</code> and all its subclasses, as well as the exceptions
   *     represented by this set.
   * @throws ThrowableSet.AlreadyHasExclusionsException if this <code>ThrowableSet</code> is the
   *     result of a {@link #whichCatchableAs(RefType)} operation and, thus, unable to represent the
   *     addition of <code>e</code>.
   */
  public ThrowableSet add(AnySubType e) throws ThrowableSet.AlreadyHasExclusionsException {
    if (INSTRUMENTING) {
      Manager.v().addsOfAnySubType++;
    }

    ThrowableSet result = getMemoizedAdds(e);
    if (result != null) {
      if (INSTRUMENTING) {
        Manager.v().addsInclusionFromMemo++;
        Manager.v().addsExclusionWithoutSearch++;
      }
      return result;
    } else {
      FastHierarchy hierarchy = Scene.v().getOrMakeFastHierarchy();
      RefType newBase = e.getBase();

      if (INSTRUMENTING) {
        if (exceptionsExcluded.size() != 0) {
          Manager.v().addsExclusionWithSearch++;
        } else {
          Manager.v().addsExclusionWithoutSearch++;
        }
      }
      for (Iterator i = exceptionsExcluded.iterator(); i.hasNext(); ) {
        RefType exclusionBase = ((AnySubType) i.next()).getBase();
        if (hierarchy.canStoreType(newBase, exclusionBase)
            || hierarchy.canStoreType(exclusionBase, newBase)) {
          if (INSTRUMENTING) {
            // To ensure that the subcategories total properly:
            Manager.v().addsInclusionInterrupted++;
          }
          throw new AlreadyHasExclusionsException(
              "ThrowableSet.add("
                  + e.toString()
                  + ") to the set [ "
                  + this.toString()
                  + "] where "
                  + exclusionBase.toString()
                  + " is excluded.");
        }
      }

      if (this.exceptionsIncluded.contains(e)) {
        if (INSTRUMENTING) {
          Manager.v().addsInclusionFromMap++;
        }
        return this;

      } else {
        if (INSTRUMENTING) {
          Manager.v().addsInclusionFromSearch++;
        }

        int changes = 0;
        boolean addNewException = true;
        Set resultSet = new HashSet();

        for (Iterator i = this.exceptionsIncluded.iterator(); i.hasNext(); ) {
          RefLikeType incumbent = (RefLikeType) i.next();
          if (incumbent instanceof RefType) {
            if (hierarchy.canStoreType(incumbent, newBase)) {
              // Omit incumbent from result.
              changes++;
            } else {
              resultSet.add(incumbent);
            }
          } else if (incumbent instanceof AnySubType) {
            RefType incumbentBase = ((AnySubType) incumbent).getBase();
            // We have to use the base types in these hierarchy calls
            // because we want to know if _all_ possible
            // types represented by e can be represented by
            // the incumbent, or vice versa.
            if (hierarchy.canStoreType(newBase, incumbentBase)) {
              addNewException = false;
              resultSet.add(incumbent);
            } else if (hierarchy.canStoreType(incumbentBase, newBase)) {
              // Omit incumbent from result;
              changes++;
            } else {
              resultSet.add(incumbent);
            }
          } else { // assertion failure.
            throw new IllegalStateException(
                "ThrowableSet.add(AnySubType): Set element "
                    + incumbent.toString()
                    + " is neither a RefType nor an AnySubType.");
          }
        }
        if (addNewException) {
          resultSet.add(e);
          changes++;
        }
        if (changes > 0) {
          result = Manager.v().registerSetIfNew(resultSet, this.exceptionsExcluded);
        } else {
          result = this;
        }
        memoizedAdds.put(e, result);
        return result;
      }
    }
  }
Example #22
0
  /**
   * Returns a <code>ThrowableSet</code> which contains <code>e</code> in addition to the exceptions
   * in this <code>ThrowableSet</code>.
   *
   * <p>Add <code>e</code> as a {@link RefType} when you know that the run-time class of the
   * exception you are representing is necessarily <code>e</code> and cannot be a subclass of <code>
   * e</code>.
   *
   * <p>For example, if you were recording the type of the exception thrown by
   *
   * <pre>
   * throw new IOException("Permission denied");
   * </pre>
   *
   * you would call
   *
   * <pre>
   * <code>add(Scene.v().getRefType("java.lang.Exception.IOException"))</code>
   * </pre>
   *
   * since the class of the exception is necessarily <code>IOException</code>.
   *
   * @param e the exception class
   * @return a set containing <code>e</code> as well as the exceptions in this set.
   * @throws {@link ThrowableSet.IllegalStateException} if this <code>ThrowableSet</code> is the
   *     result of a {@link #whichCatchableAs(RefType)} operation and, thus, unable to represent the
   *     addition of <code>e</code>.
   */
  public ThrowableSet add(RefType e) throws ThrowableSet.AlreadyHasExclusionsException {
    if (INSTRUMENTING) {
      Manager.v().addsOfRefType++;
    }
    if (this.exceptionsIncluded.contains(e)) {
      if (INSTRUMENTING) {
        Manager.v().addsInclusionFromMap++;
        Manager.v().addsExclusionWithoutSearch++;
      }
      return this;
    } else {
      ThrowableSet result = getMemoizedAdds(e);
      if (result != null) {
        if (INSTRUMENTING) {
          Manager.v().addsInclusionFromMemo++;
          Manager.v().addsExclusionWithoutSearch++;
        }
        return result;
      } else {
        if (INSTRUMENTING) {
          Manager.v().addsInclusionFromSearch++;
          if (exceptionsExcluded.size() != 0) {
            Manager.v().addsExclusionWithSearch++;
          } else {
            Manager.v().addsExclusionWithoutSearch++;
          }
        }
        FastHierarchy hierarchy = Scene.v().getOrMakeFastHierarchy();

        for (Iterator i = exceptionsExcluded.iterator(); i.hasNext(); ) {
          RefType exclusionBase = ((AnySubType) i.next()).getBase();
          if (hierarchy.canStoreType(e, exclusionBase)) {
            throw new AlreadyHasExclusionsException(
                "ThrowableSet.add(RefType): adding"
                    + e.toString()
                    + " to the set [ "
                    + this.toString()
                    + "] where "
                    + exclusionBase.toString()
                    + " is excluded.");
          }
        }

        for (Iterator i = exceptionsIncluded.iterator(); i.hasNext(); ) {
          RefLikeType incumbent = (RefLikeType) i.next();
          if (incumbent instanceof AnySubType) {
            // Need to use incumbent.getBase() because
            // hierarchy.canStoreType() assumes that parent
            // is not an AnySubType.
            RefType incumbentBase = ((AnySubType) incumbent).getBase();
            if (hierarchy.canStoreType(e, incumbentBase)) {
              memoizedAdds.put(e, this);
              return this;
            }
          } else if (!(incumbent instanceof RefType)) {
            // assertion failure.
            throw new IllegalStateException(
                "ThrowableSet.add(RefType): Set element "
                    + incumbent.toString()
                    + " is neither a RefType nor an AnySubType.");
          }
        }
        Set resultSet = new HashSet(this.exceptionsIncluded);
        resultSet.add(e);
        result = Manager.v().registerSetIfNew(resultSet, this.exceptionsExcluded);
        memoizedAdds.put(e, result);
        return result;
      }
    }
  }
Example #23
0
    /**
     * Constructs a <code>ThrowableSet.Manager</code> for inclusion in Soot's global variable
     * manager, {@link G}.
     *
     * @param g guarantees that the constructor may only be called from {@link Singletons}.
     */
    public Manager(Singletons.Global g) {
      // First ensure the Exception classes are represented in Soot.

      // Runtime errors:
      RUNTIME_EXCEPTION = Scene.v().getRefType("java.lang.RuntimeException");
      ARITHMETIC_EXCEPTION = Scene.v().getRefType("java.lang.ArithmeticException");
      ARRAY_STORE_EXCEPTION = Scene.v().getRefType("java.lang.ArrayStoreException");
      CLASS_CAST_EXCEPTION = Scene.v().getRefType("java.lang.ClassCastException");
      ILLEGAL_MONITOR_STATE_EXCEPTION =
          Scene.v().getRefType("java.lang.IllegalMonitorStateException");
      INDEX_OUT_OF_BOUNDS_EXCEPTION = Scene.v().getRefType("java.lang.IndexOutOfBoundsException");
      ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION =
          Scene.v().getRefType("java.lang.ArrayIndexOutOfBoundsException");
      NEGATIVE_ARRAY_SIZE_EXCEPTION = Scene.v().getRefType("java.lang.NegativeArraySizeException");
      NULL_POINTER_EXCEPTION = Scene.v().getRefType("java.lang.NullPointerException");

      INSTANTIATION_ERROR = Scene.v().getRefType("java.lang.InstantiationError");

      EMPTY = registerSetIfNew(null, null);

      Set allThrowablesSet = new HashSet();
      allThrowablesSet.add(AnySubType.v(Scene.v().getRefType("java.lang.Throwable")));
      ALL_THROWABLES = registerSetIfNew(allThrowablesSet, null);

      Set vmErrorSet = new HashSet();
      vmErrorSet.add(Scene.v().getRefType("java.lang.InternalError"));
      vmErrorSet.add(Scene.v().getRefType("java.lang.OutOfMemoryError"));
      vmErrorSet.add(Scene.v().getRefType("java.lang.StackOverflowError"));
      vmErrorSet.add(Scene.v().getRefType("java.lang.UnknownError"));

      // The Java library's deprecated Thread.stop(Throwable) method
      // would actually allow _any_ Throwable to be delivered
      // asynchronously, not just java.lang.ThreadDeath.
      vmErrorSet.add(Scene.v().getRefType("java.lang.ThreadDeath"));

      VM_ERRORS = registerSetIfNew(vmErrorSet, null);

      Set resolveClassErrorSet = new HashSet();
      resolveClassErrorSet.add(Scene.v().getRefType("java.lang.ClassCircularityError"));
      // We add AnySubType(ClassFormatError) so that we can
      // avoid adding its subclass,
      // UnsupportedClassVersionError, explicitly.  This is a
      // hack to allow Soot to analyze older class libraries
      // (UnsupportedClassVersionError was added in JDK 1.2).

      // TODO: The class "ClassFormatError" does not exist in TakaTuka so our best guess is that
      // 			commenting the following line out won't affect the analysis in any way. But this
      //			is a "fault point" to look at if any problems arise in the future.
      // resolveClassErrorSet.add(AnySubType.v(Scene.v().getRefType("java.lang.ClassFormatError")));
      resolveClassErrorSet.add(Scene.v().getRefType("java.lang.IllegalAccessError"));
      resolveClassErrorSet.add(Scene.v().getRefType("java.lang.IncompatibleClassChangeError"));
      resolveClassErrorSet.add(Scene.v().getRefType("java.lang.LinkageError"));
      resolveClassErrorSet.add(Scene.v().getRefType("java.lang.NoClassDefFoundError"));
      resolveClassErrorSet.add(Scene.v().getRefType("java.lang.VerifyError"));
      RESOLVE_CLASS_ERRORS = registerSetIfNew(resolveClassErrorSet, null);

      Set resolveFieldErrorSet = new HashSet(resolveClassErrorSet);
      resolveFieldErrorSet.add(Scene.v().getRefType("java.lang.NoSuchFieldError"));
      RESOLVE_FIELD_ERRORS = registerSetIfNew(resolveFieldErrorSet, null);

      Set resolveMethodErrorSet = new HashSet(resolveClassErrorSet);
      resolveMethodErrorSet.add(Scene.v().getRefType("java.lang.AbstractMethodError"));
      resolveMethodErrorSet.add(Scene.v().getRefType("java.lang.NoSuchMethodError"));
      resolveMethodErrorSet.add(Scene.v().getRefType("java.lang.UnsatisfiedLinkError"));
      RESOLVE_METHOD_ERRORS = registerSetIfNew(resolveMethodErrorSet, null);

      // The static initializers of a newly loaded class might
      // throw any Error (if they threw an Exception---even a
      // RuntimeException---it would be replaced by an
      // ExceptionInInitializerError):
      //
      Set initializationErrorSet = new HashSet();
      initializationErrorSet.add(AnySubType.v(Scene.v().getRefType("java.lang.Error")));
      INITIALIZATION_ERRORS = registerSetIfNew(initializationErrorSet, null);
    }
Example #24
0
 private void checkState() {
   if (state != sc.getState())
     throw new ConcurrentModificationException("Scene changed for Hierarchy!");
 }
Example #25
0
  public static void writeScene(
      Scene theScene, m2 out, boolean wholeScene, double tol, boolean smooth, boolean inject) {
    // Write the objects in the scene.

    int numVert = 0, numNorm = 0, numTexVert = 0;
    Hashtable<String, String> groupNames = new Hashtable<String, String>();
    NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
    nf.setMaximumFractionDigits(5);
    nf.setGroupingUsed(false);
    for (int i = 0; i < theScene.getNumObjects(); i++) {
      // Get a rendering mesh for the object.

      ObjectInfo info = theScene.getObject(i);
      if (!wholeScene && !info.selected) continue;
      if (info.getObject().getTexture() == null) continue;
      FacetedMesh mesh;

      if (!smooth && info.getObject() instanceof FacetedMesh) mesh = (FacetedMesh) info.getObject();
      else mesh = info.getObject().convertToTriangleMesh(tol);
      if (mesh == null) continue;

      // Find the normals.

      Vec3 norm[];
      int normIndex[][] = new int[mesh.getFaceCount()][];
      if (mesh instanceof TriangleMesh) {
        RenderingMesh rm = ((TriangleMesh) mesh).getRenderingMesh(Double.MAX_VALUE, false, info);
        norm = rm.norm;
        for (int j = 0; j < normIndex.length; j++)
          normIndex[j] = new int[] {rm.triangle[j].n1, rm.triangle[j].n2, rm.triangle[j].n3};
      } else {
        norm = mesh.getNormals();
        for (int j = 0; j < normIndex.length; j++) {
          normIndex[j] = new int[mesh.getFaceVertexCount(j)];
          for (int k = 0; k < normIndex[j].length; k++)
            normIndex[j][k] = mesh.getFaceVertexIndex(j, k);
        }
      }
      // Write out the object.

      Mat4 trans = info.getCoords().fromLocal();
      MeshVertex vert[] = mesh.getVertices();

      System.out.println("nVertixes:\t" + out.vertex.length);
      for (int j = 0; j < vert.length; j++) {
        Vec3 v = trans.times(vert[j].r);
        float[] tf = new float[3];
        tf[0] = (float) v.x;
        tf[1] = (float) v.y;
        tf[2] = (float) v.z;
        out.vertex[j].setVertexPos(tf);
      }
      /*short faceCount[][]=new short[mesh.getFaceCount()][3];
      for(int f=0;f<mesh.getFaceCount();f++){
       faceCount[f][0]=(short) mesh.getFaceVertexIndex(f, 0);
       faceCount[f][1]=(short) mesh.getFaceVertexIndex(f, 1);
       faceCount[f][2]=(short) mesh.getFaceVertexIndex(f, 2);
      }
      System.out.println("Old nTriangles:\t"+out.movi.nTriangles);
      out.movi.setnewSize(faceCount.length, inject);
      out.movi.render();
      System.out.println("New nTriangles:\t"+out.movi.nTriangles);
      for (int j = 0; j < faceCount.length; j++)
        {
          out.movi.setnewIndex(j, faceCount[j]);

        }

      if(useuv==true){
      UVMapping uvmap=(UVMapping) info.getObject().getTextureMapping();
      Vec2 uv[]=uvmap.findTextureCoordinates(mesh);
      out.motv.setnewSize(out.movt.nVertices, inject);
      for(int n=0;n<out.movt.nVertices;n++){
       if(n<=uv.length){
       float[] txcoord={(float) uv[n].x,(float) uv[n].y};
       out.motv.setnewTexVertex(n, txcoord);}
       else{
        float[] txcoord={0.0f,0.0f};
        out.motv.setnewTexVertex(n, txcoord);
       }
      }}
      if(inject==false){
      out.moba.setnewSize(1, false);
      out.movt.render();
      out.movi.render();
      out.moba.entrys[0]=new MOBA_Entry((short)0,(short)out.movt.nVertices,0,out.movi.nTriangles);
      out.mobn.setnewSize(1, false);
      out.mobn.entrys[0]=new MOBN_Entry(out.movi.nTriangles, 1);
      }*/
      /* out.monr.setnewSize(norm.length);
      out.monr.render();
      for (int j = 0; j < norm.length; j++)
        {
       float[] tf = new float[3];
          if (norm[j] == null){
        	  tf[0]=1f;tf[1]=0f;tf[2]=0f;
        	  out.monr.setNormalPos(j, tf);}
          else
            {
              Vec3 v = trans.timesDirection(norm[j]);
              tf[0]=(float) v.x;tf[1]=(float) v.y;tf[2]=(float)v.z;
              out.monr.setnewNormalPos(j, tf);
            }
        }*/

      numVert += vert.length;
      numNorm += norm.length;
    }
    save(out);
  }
Example #26
0
 /** Constructs a JimpleLocal of the given name and type. */
 public JimpleLocal(String name, Type t) {
   this.name = name.intern();
   this.type = t;
   Scene.v().getLocalNumberer().add(this);
 }
  /*
   * Generates the sequence of instructions needed to instrument ifStmtUnit
   *
   * @param ifStmtUnit: the unit to be instrumented
   * @return A Chain of Units that represent the instrumentation of ifStmtUnit
   */
  private static Chain<Unit> generateInstrumentationUnits(Unit ifStmtUnit, Body b) {

    AbstractBinopExpr expression =
        (AbstractBinopExpr)
            ((JIfStmt) ifStmtUnit).getCondition(); // implementation of AbstractBinopExpr
    Value operand1 = expression.getOp1();
    Value operand2 = expression.getOp2();

    JimpleLocal op1Local = (JimpleLocal) operand1;

    // Local localOperand = Jimple.v().newLocal("op1", operand1.getType());
    // b.getLocals().add(localOperand);

    // We need to use these operand as Locals or constants
    /**
     * JimpleLocal test; if(operand1 instanceof soot.jimple.internal.JimpleLocal) test =
     * (JimpleLocal)operand1; else test = null;
     */
    String op = expression.getClass().toString();

    Chain<Unit> resultUnits = new HashChain<Unit>();
    Local tmpRef;
    // Add locals directely on the top of the body, java.io.printStream tmpRef
    tmpRef = Jimple.v().newLocal("tmpRef", RefType.v("java.io.PrintStream"));
    b.getLocals().addFirst(tmpRef);

    // add "tmpRef = java.lang.System.out"
    resultUnits.add(
        Jimple.v()
            .newAssignStmt(
                tmpRef,
                Jimple.v()
                    .newStaticFieldRef(
                        Scene.v()
                            .getField("<java.lang.System: java.io.PrintStream out>")
                            .makeRef())));
    {
      SootMethod toCall =
          Scene.v().getMethod("<java.io.PrintStream: void println(java.lang.String)>");
      resultUnits.add(
          Jimple.v()
              .newInvokeStmt(
                  Jimple.v()
                      .newVirtualInvokeExpr(
                          tmpRef, toCall.makeRef(), StringConstant.v("Operande 1: "))));
      resultUnits.add(
          Jimple.v()
              .newInvokeStmt(
                  Jimple.v()
                      .newVirtualInvokeExpr(
                          tmpRef,
                          toCall.makeRef(),
                          StringConstant.v(operand1.getClass().toString()))));

      resultUnits.add(
          Jimple.v()
              .newInvokeStmt(
                  Jimple.v()
                      .newVirtualInvokeExpr(
                          tmpRef, toCall.makeRef(), StringConstant.v("Operande 2:"))));

      resultUnits.add(
          Jimple.v()
              .newInvokeStmt(
                  Jimple.v()
                      .newVirtualInvokeExpr(
                          tmpRef,
                          toCall.makeRef(),
                          StringConstant.v(operand2.getClass().toString()))));

      resultUnits.add(
          Jimple.v()
              .newInvokeStmt(
                  Jimple.v()
                      .newVirtualInvokeExpr(
                          tmpRef, toCall.makeRef(), StringConstant.v("Operateur: "))));

      resultUnits.add(
          Jimple.v()
              .newInvokeStmt(
                  Jimple.v().newVirtualInvokeExpr(tmpRef, toCall.makeRef(), StringConstant.v(op))));
    }

    return resultUnits;
  }
Example #28
0
  /**
   * Partitions the exceptions in this <code>ThrowableSet</code> into those which would be caught by
   * a handler with the passed <code>catch</code> parameter type and those which would not.
   *
   * @param catcher type of the handler parameter to be tested.
   * @return a pair of <code>ThrowableSet</code>s, one containing the types in this <code>
   *     ThrowableSet</code> which would be be caught as <code>catcher</code> and the other
   *     containing the types in this <code>ThrowableSet</code> which would not be caught as <code>
   *     catcher</code>.
   */
  public Pair whichCatchableAs(RefType catcher) {
    if (INSTRUMENTING) {
      Manager.v().removesOfAnySubType++;
    }

    FastHierarchy h = Scene.v().getOrMakeFastHierarchy();
    Set caughtIncluded = null;
    Set caughtExcluded = null;
    Set uncaughtIncluded = null;
    Set uncaughtExcluded = null;

    if (INSTRUMENTING) {
      Manager.v().removesFromSearch++;
    }

    for (Iterator i = exceptionsExcluded.iterator(); i.hasNext(); ) {
      AnySubType exclusion = (AnySubType) i.next();
      RefType exclusionBase = exclusion.getBase();
      if (h.canStoreType(catcher, exclusionBase)) {
        // Because the add() operations ban additions to sets
        // with exclusions, we can be sure no types in this are
        // caught by catcher.
        return new Pair(ThrowableSet.Manager.v().EMPTY, this);
      } else if (h.canStoreType(exclusionBase, catcher)) {
        // exclusion wouldn't be in exceptionsExcluded if one
        // of its supertypes were not in exceptionsIncluded,
        // so we know the next loop will add either that supertype
        // or catcher to caughtIncluded.  Thus:
        caughtExcluded = addExceptionToSet(exclusion, caughtExcluded);
      } else {
        uncaughtExcluded = addExceptionToSet(exclusion, uncaughtExcluded);
      }
    }

    for (Iterator i = exceptionsIncluded.iterator(); i.hasNext(); ) {
      RefLikeType inclusion = (RefLikeType) i.next();
      if (inclusion instanceof RefType) {
        if (h.canStoreType(inclusion, catcher)) {
          caughtIncluded = addExceptionToSet(inclusion, caughtIncluded);
        } else {
          uncaughtIncluded = addExceptionToSet(inclusion, uncaughtIncluded);
        }
      } else {
        RefType base = ((AnySubType) inclusion).getBase();
        if (h.canStoreType(base, catcher)) {
          // All subtypes of base will be caught.  Any exclusions
          // will already have been copied to caughtExcluded by
          // the preceding loop.
          caughtIncluded = addExceptionToSet(inclusion, caughtIncluded);
        } else if (h.canStoreType(catcher, base)) {
          // Some subtypes of base will be caught, and
          // we know that not all of those catchable subtypes
          // are among exceptionsExcluded, since in that case we
          // would already have returned from within the
          // preceding loop.  So, remove AnySubType(catcher)
          // from the uncaught types.
          uncaughtIncluded = addExceptionToSet(inclusion, uncaughtIncluded);
          uncaughtExcluded = addExceptionToSet(AnySubType.v(catcher), uncaughtExcluded);
          caughtIncluded = addExceptionToSet(AnySubType.v(catcher), caughtIncluded);
          // Any already excluded subtypes of inclusion
          // which are subtypes of catcher will have been
          // added to caughtExcluded by the previous loop.
        } else {
          uncaughtIncluded = addExceptionToSet(inclusion, uncaughtIncluded);
        }
      }
    }
    ThrowableSet caughtSet = Manager.v().registerSetIfNew(caughtIncluded, caughtExcluded);
    ThrowableSet uncaughtSet = Manager.v().registerSetIfNew(uncaughtIncluded, uncaughtExcluded);
    return new Pair(caughtSet, uncaughtSet);
  }
Example #29
0
  /** Constructs a hierarchy from the current scene. */
  public Hierarchy() {
    this.sc = Scene.v();
    state = sc.getState();

    // Well, this used to be describable by 'Duh'.
    // Construct the subclasses hierarchy and the subinterfaces hierarchy.
    {
      Chain allClasses = sc.getClasses();

      classToSubclasses = new HashMap<SootClass, List<SootClass>>(allClasses.size() * 2 + 1, 0.7f);
      interfaceToSubinterfaces =
          new HashMap<SootClass, List<SootClass>>(allClasses.size() * 2 + 1, 0.7f);

      classToDirSubclasses = new HashMap<SootClass, List>(allClasses.size() * 2 + 1, 0.7f);
      interfaceToDirSubinterfaces = new HashMap<SootClass, List>(allClasses.size() * 2 + 1, 0.7f);
      interfaceToDirImplementers = new HashMap<SootClass, List>(allClasses.size() * 2 + 1, 0.7f);

      Iterator classesIt = allClasses.iterator();
      while (classesIt.hasNext()) {
        SootClass c = (SootClass) classesIt.next();
        if (c.resolvingLevel() < SootClass.HIERARCHY) continue;

        if (c.isInterface()) {
          interfaceToDirSubinterfaces.put(c, new ArrayList());
          interfaceToDirImplementers.put(c, new ArrayList());
        } else classToDirSubclasses.put(c, new ArrayList());
      }

      classesIt = allClasses.iterator();
      while (classesIt.hasNext()) {
        SootClass c = (SootClass) classesIt.next();
        if (c.resolvingLevel() < SootClass.HIERARCHY) continue;

        if (c.hasSuperclass()) {
          if (c.isInterface()) {
            Iterator subIt = c.getInterfaces().iterator();

            while (subIt.hasNext()) {
              SootClass i = (SootClass) subIt.next();
              if (c.resolvingLevel() < SootClass.HIERARCHY) continue;
              List<SootClass> l = interfaceToDirSubinterfaces.get(i);
              l.add(c);
            }
          } else {
            List<SootClass> l = classToDirSubclasses.get(c.getSuperclass());
            l.add(c);

            Iterator subIt = c.getInterfaces().iterator();

            while (subIt.hasNext()) {
              SootClass i = (SootClass) subIt.next();
              if (c.resolvingLevel() < SootClass.HIERARCHY) continue;
              l = interfaceToDirImplementers.get(i);
              l.add(c);
            }
          }
        }
      }

      // Fill the directImplementers lists with subclasses.
      {
        classesIt = allClasses.iterator();
        while (classesIt.hasNext()) {
          SootClass c = (SootClass) classesIt.next();
          if (c.resolvingLevel() < SootClass.HIERARCHY) continue;
          if (c.isInterface()) {
            List<SootClass> imp = interfaceToDirImplementers.get(c);
            Set<SootClass> s = new ArraySet();

            Iterator<SootClass> impIt = imp.iterator();
            while (impIt.hasNext()) {
              SootClass c0 = impIt.next();
              if (c.resolvingLevel() < SootClass.HIERARCHY) continue;
              s.addAll(getSubclassesOfIncluding(c0));
            }

            imp.clear();
            imp.addAll(s);
          }
        }
      }

      classesIt = allClasses.iterator();
      while (classesIt.hasNext()) {
        SootClass c = (SootClass) classesIt.next();
        if (c.resolvingLevel() < SootClass.HIERARCHY) continue;

        if (c.isInterface()) {
          interfaceToDirSubinterfaces.put(
              c, Collections.unmodifiableList(interfaceToDirSubinterfaces.get(c)));
          interfaceToDirImplementers.put(
              c, Collections.unmodifiableList(interfaceToDirImplementers.get(c)));
        } else
          classToDirSubclasses.put(c, Collections.unmodifiableList(classToDirSubclasses.get(c)));
      }
    }
  }
Example #30
0
 public void outASigFieldRef(ASigFieldRef node) {
   SootFieldRef field = (SootFieldRef) mProductions.removeLast();
   field = Scene.v().makeFieldRef(field.declaringClass(), field.name(), field.type(), true);
   mProductions.addLast(Jimple.v().newStaticFieldRef(field));
 }