Package soot

Examples of soot.Body


      SootMethod container = guard.container;
      Stmt insertionPoint = guard.stmt;
      if(!container.hasActiveBody()) {
        G.v().out.println("WARNING: Tried to insert guard into "+container+" but couldn't because method has no body.");
      } else {
        Body body = container.getActiveBody();
       
        //exc = new Error
        RefType runtimeExceptionType = RefType.v("java.lang.Error");
        NewExpr newExpr = Jimple.v().newNewExpr(runtimeExceptionType);
        LocalGenerator lg = new LocalGenerator(body);
        Local exceptionLocal = lg.generateLocal(runtimeExceptionType);
        AssignStmt assignStmt = Jimple.v().newAssignStmt(exceptionLocal, newExpr);
        body.getUnits().insertBefore(assignStmt, insertionPoint);
       
        //exc.<init>(message)
        SootMethodRef cref = runtimeExceptionType.getSootClass().getMethod("<init>", Collections.singletonList(RefType.v("java.lang.String"))).makeRef();
        SpecialInvokeExpr constructorInvokeExpr = Jimple.v().newSpecialInvokeExpr(exceptionLocal, cref, StringConstant.v(guard.message));
        InvokeStmt initStmt = Jimple.v().newInvokeStmt(constructorInvokeExpr);
        body.getUnits().insertAfter(initStmt, assignStmt);
       
        if(options.guards().equals("print")) {
          //exc.printStackTrace();
          VirtualInvokeExpr printStackTraceExpr = Jimple.v().newVirtualInvokeExpr(exceptionLocal, Scene.v().getSootClass("java.lang.Throwable").getMethod("printStackTrace", Collections.emptyList()).makeRef());
          InvokeStmt printStackTraceStmt = Jimple.v().newInvokeStmt(printStackTraceExpr);
          body.getUnits().insertAfter(printStackTraceStmt, initStmt);
        } else if(options.guards().equals("throw")) {
          body.getUnits().insertAfter(Jimple.v().newThrowStmt(exceptionLocal), initStmt);
        } else {
          throw new RuntimeException("Invalid value for phase option (guarding): "+options.guards());
        }
      }
    }
View Full Code Here


    }
    private void processNewMethod( SootMethod m ) {
        if( m.isNative() || m.isPhantom() ) {
            return;
        }
        Body b = m.retrieveActiveBody();
        getImplicitTargets( m );
        findReceivers(m, b);
    }
View Full Code Here

        final SootClass scl = source.getDeclaringClass();
        if( source.isNative() || source.isPhantom() ) return;
        if( source.getSubSignature().indexOf( "<init>" ) >= 0 ) {
            handleInit(source, scl);
        }
        Body b = source.retrieveActiveBody();
        for( Iterator sIt = b.getUnits().iterator(); sIt.hasNext(); ) {
            final Stmt s = (Stmt) sIt.next();
            if( s.containsInvokeExpr() ) {
                InvokeExpr ie = s.getInvokeExpr();
                if( ie.getMethodRef().getSignature().equals( "<java.lang.reflect.Method: java.lang.Object invoke(java.lang.Object,java.lang.Object[])>" ) ) {
                  reflectionModel.methodInvoke(source,s);
View Full Code Here

      for (SootMethod sootMethod : methodsWithRightName) {
        if(coversLineNumber(lineNumber, sootMethod)) {
          return Collections.singleton(sootMethod);
        }
        if(sootMethod.hasActiveBody()) {
          Body body = sootMethod.getActiveBody();
          if(coversLineNumber(lineNumber, body)) {
            return Collections.singleton(sootMethod);
          }
          for (Unit u : body.getUnits()) {
            if(coversLineNumber(lineNumber, u)) {
              return Collections.singleton(sootMethod);
            }
          }
        }
View Full Code Here

            //             // we have to do this seemingly useless
            //             // thing, since the scene caches a pointer
            //             // to the method based on it's parameter types.
            //             theClass.removeMethod(newMethod);
            //             theClass.addMethod(newMethod);
            Body newBody = newMethod.retrieveActiveBody();

            // Analyze what object each local points to.
            NamedObjAnalysis analysis = new NamedObjAnalysis(newMethod,
                    ModelTransformer.getObjectForClass(theClass));

            for (Iterator locals = newBody.getLocals().iterator(); locals
                    .hasNext();) {
                Local local = (Local) locals.next();
                Type type = local.getType();

                try {
                    if (type instanceof RefType
                            && (((RefType) type).getSootClass() == oldClass)
                            && (object == analysis.getObject(local))) {
                        local.setType(RefType.v(newClass));
                    }
                } catch (Exception ex) {
                    if (_debug) {
                        System.out.println("Exception on local = " + ex);
                    }
                }
            }

            Iterator j = newBody.getUnits().iterator();

            while (j.hasNext()) {
                Unit unit = (Unit) j.next();

                // System.out.println("unit = " + unit);
View Full Code Here

        ArrayList methodList = new ArrayList(theClass.getMethods());

        for (Iterator methods = methodList.iterator(); methods.hasNext();) {
            SootMethod newMethod = (SootMethod) methods.next();

            Body newBody = newMethod.retrieveActiveBody();
            Iterator j = newBody.getUnits().iterator();

            while (j.hasNext()) {
                Unit unit = (Unit) j.next();
                Iterator boxes = unit.getUseAndDefBoxes().iterator();
View Full Code Here

            // thing, since the scene caches a pointer
            // to the method based on it's parameter types.
            theClass.removeMethod(newMethod);
            theClass.addMethod(newMethod);

            Body newBody = newMethod.retrieveActiveBody();

            for (Iterator locals = newBody.getLocals().iterator(); locals
                    .hasNext();) {
                Local local = (Local) locals.next();
                Type type = local.getType();

                if (type instanceof RefType
                        && (((RefType) type).getSootClass() == oldClass)) {
                    local.setType(RefType.v(newClass));
                }
            }

            Iterator j = newBody.getUnits().iterator();

            while (j.hasNext()) {
                Unit unit = (Unit) j.next();
                Iterator boxes = unit.getUseAndDefBoxes().iterator();
                //  System.out.println("unit = " + unit);
View Full Code Here

        // over all the methods in the class twice, which could get
        // very expensive.
        for (Iterator methods = theClass.getMethods().iterator(); methods
                .hasNext();) {
            SootMethod newMethod = (SootMethod) methods.next();
            Body newBody = newMethod.retrieveActiveBody();

            // use a snapshotIterator since we are going to be manipulating
            // the statements.
            Iterator j = newBody.getUnits().snapshotIterator();

            while (j.hasNext()) {
                Stmt stmt = (Stmt) j.next();

                System.out.println("stmt = " + stmt);
View Full Code Here

        for (Iterator methods = theClass.getMethods().iterator(); methods
                .hasNext();) {
            SootMethod method = (SootMethod) methods.next();

            // System.out.println("method = " + method.getSignature());
            Body body = method.retrieveActiveBody();

            // use a snapshotIterator since we are going to be manipulating
            // the statements.
            Iterator j = body.getUnits().snapshotIterator();

            while (j.hasNext()) {
                Stmt stmt = (Stmt) j.next();

                if (stmt.containsInvokeExpr()) {
View Full Code Here

            System.out.println("output flow = " + out.hasEffects() + " "
                    + out.effectSet());
        }

        // A method has side effects if it sets the values of any fields.
        Body body = method.retrieveActiveBody();
        Scene.v().releaseActiveHierarchy();

        for (Iterator units = body.getUnits().iterator(); units.hasNext();) {
            Unit unit = (Unit) units.next();

            if (_debug) {
                System.out.println("unit = " + unit);
            }
View Full Code Here

TOP

Related Classes of soot.Body

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.