Search in sources :

Example 1 with CGOptions

use of soot.options.CGOptions in project soot by Sable.

the class Scene method addReflectionTraceClasses.

private void addReflectionTraceClasses() {
    CGOptions options = new CGOptions(PhaseOptions.v().getPhaseOptions("cg"));
    String log = options.reflection_log();
    Set<String> classNames = new HashSet<String>();
    if (log != null && log.length() > 0) {
        BufferedReader reader = null;
        String line = "";
        try {
            reader = new BufferedReader(new InputStreamReader(new FileInputStream(log)));
            while ((line = reader.readLine()) != null) {
                if (line.length() == 0)
                    continue;
                String[] portions = line.split(";", -1);
                String kind = portions[0];
                String target = portions[1];
                String source = portions[2];
                String sourceClassName = source.substring(0, source.lastIndexOf("."));
                classNames.add(sourceClassName);
                if (kind.equals("Class.forName")) {
                    classNames.add(target);
                } else if (kind.equals("Class.newInstance")) {
                    classNames.add(target);
                } else if (kind.equals("Method.invoke") || kind.equals("Constructor.newInstance")) {
                    classNames.add(signatureToClass(target));
                } else if (kind.equals("Field.set*") || kind.equals("Field.get*")) {
                    classNames.add(signatureToClass(target));
                } else
                    throw new RuntimeException("Unknown entry kind: " + kind);
            }
        } catch (Exception e) {
            throw new RuntimeException("Line: '" + line + "'", e);
        } finally {
            if (reader != null)
                try {
                    reader.close();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
        }
    }
    for (String c : classNames) {
        addBasicClass(c, SootClass.BODIES);
    }
}
Also used : CGOptions(soot.options.CGOptions) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) HashSet(java.util.HashSet)

Example 2 with CGOptions

use of soot.options.CGOptions in project soot by Sable.

the class ReflectiveCallsInliner method internalTransform.

@Override
protected void internalTransform(String phaseName, @SuppressWarnings("rawtypes") Map options) {
    if (!initialized) {
        CGOptions cgOptions = new CGOptions(PhaseOptions.v().getPhaseOptions("cg"));
        String logFilePath = cgOptions.reflection_log();
        RTI = new ReflectionTraceInfo(logFilePath);
        Scene.v().getSootClass(SootSig.class.getName()).setApplicationClass();
        Scene.v().getSootClass(UnexpectedReflectiveCall.class.getName()).setApplicationClass();
        Scene.v().getSootClass(IUnexpectedReflectiveCallHandler.class.getName()).setApplicationClass();
        Scene.v().getSootClass(DefaultHandler.class.getName()).setApplicationClass();
        Scene.v().getSootClass(OpaquePredicate.class.getName()).setApplicationClass();
        Scene.v().getSootClass(ReflectiveCalls.class.getName()).setApplicationClass();
        reflectiveCallsClass = new SootClass("soot.rtlib.tamiflex.ReflectiveCallsWrapper", Modifier.PUBLIC);
        Scene.v().addClass(reflectiveCallsClass);
        reflectiveCallsClass.setApplicationClass();
        UNINTERPRETED_METHOD = Scene.v().makeMethodRef(Scene.v().getSootClass("soot.rtlib.tamiflex.OpaquePredicate"), "getFalse", Collections.<Type>emptyList(), BooleanType.v(), true);
        if (useCaching)
            addCaching();
        initializeReflectiveCallsTable();
        callSiteId = 0;
        callNum = 0;
        initialized = true;
    }
    for (SootMethod m : RTI.methodsContainingReflectiveCalls()) {
        m.retrieveActiveBody();
        Body b = m.getActiveBody();
        {
            Set<String> classForNameClassNames = RTI.classForNameClassNames(m);
            if (!classForNameClassNames.isEmpty()) {
                inlineRelectiveCalls(m, classForNameClassNames, ReflectionTraceInfo.Kind.ClassForName);
                if (Options.v().validate())
                    b.validate();
            }
        }
        {
            Set<String> classNewInstanceClassNames = RTI.classNewInstanceClassNames(m);
            if (!classNewInstanceClassNames.isEmpty()) {
                inlineRelectiveCalls(m, classNewInstanceClassNames, ReflectionTraceInfo.Kind.ClassNewInstance);
                if (Options.v().validate())
                    b.validate();
            }
        }
        {
            Set<String> constructorNewInstanceSignatures = RTI.constructorNewInstanceSignatures(m);
            if (!constructorNewInstanceSignatures.isEmpty()) {
                inlineRelectiveCalls(m, constructorNewInstanceSignatures, ReflectionTraceInfo.Kind.ConstructorNewInstance);
                if (Options.v().validate())
                    b.validate();
            }
        }
        {
            Set<String> methodInvokeSignatures = RTI.methodInvokeSignatures(m);
            if (!methodInvokeSignatures.isEmpty()) {
                inlineRelectiveCalls(m, methodInvokeSignatures, ReflectionTraceInfo.Kind.MethodInvoke);
                if (Options.v().validate())
                    b.validate();
            }
        }
        {
            Set<String> fieldSetSignatures = RTI.fieldSetSignatures(m);
            if (!fieldSetSignatures.isEmpty()) {
                inlineRelectiveCalls(m, fieldSetSignatures, ReflectionTraceInfo.Kind.FieldSet);
                if (Options.v().validate())
                    b.validate();
            }
        }
        {
            Set<String> fieldGetSignatures = RTI.fieldGetSignatures(m);
            if (!fieldGetSignatures.isEmpty()) {
                inlineRelectiveCalls(m, fieldGetSignatures, ReflectionTraceInfo.Kind.FieldGet);
                if (Options.v().validate())
                    b.validate();
            }
        }
        // clean up after us
        cleanup(b);
    }
}
Also used : CGOptions(soot.options.CGOptions) RefType(soot.RefType) BooleanType(soot.BooleanType) Type(soot.Type) RefLikeType(soot.RefLikeType) ArrayType(soot.ArrayType) PrimType(soot.PrimType) VoidType(soot.VoidType) Set(java.util.Set) SootMethod(soot.SootMethod) SootClass(soot.SootClass) Body(soot.Body) JimpleBody(soot.jimple.JimpleBody)

Example 3 with CGOptions

use of soot.options.CGOptions in project soot by Sable.

the class Main method autoSetOptions.

public void autoSetOptions() {
    // when no-bodies-for-excluded is enabled, also enable phantom refs
    if (Options.v().no_bodies_for_excluded())
        Options.v().set_allow_phantom_refs(true);
    // when reflection log is enabled, also enable phantom refs
    CGOptions cgOptions = new CGOptions(PhaseOptions.v().getPhaseOptions("cg"));
    String log = cgOptions.reflection_log();
    if ((log != null) && (log.length() > 0)) {
        Options.v().set_allow_phantom_refs(true);
    }
    // if phantom refs enabled,  ignore wrong staticness in type assigner
    if (Options.v().allow_phantom_refs()) {
        Options.v().set_wrong_staticness(Options.wrong_staticness_fix);
    }
}
Also used : CGOptions(soot.options.CGOptions)

Example 4 with CGOptions

use of soot.options.CGOptions in project soot by Sable.

the class CallGraphPack method internalApply.

protected void internalApply() {
    CGOptions options = new CGOptions(PhaseOptions.v().getPhaseOptions(this));
    if (!Scene.v().hasCustomEntryPoints()) {
        if (!options.implicit_entry()) {
            Scene.v().setEntryPoints(EntryPoints.v().application());
        }
        if (options.all_reachable()) {
            List<SootMethod> entryPoints = new ArrayList<SootMethod>();
            entryPoints.addAll(EntryPoints.v().all());
            entryPoints.addAll(EntryPoints.v().methodsOfApplicationClasses());
            Scene.v().setEntryPoints(entryPoints);
        }
    }
    super.internalApply();
    ClinitElimTransformer trimmer = new ClinitElimTransformer();
    if (options.trim_clinit()) {
        for (SootClass cl : Scene.v().getClasses(SootClass.BODIES)) {
            for (SootMethod m : cl.getMethods()) {
                if (m.isConcrete() && m.hasActiveBody()) {
                    trimmer.transform(m.getActiveBody());
                }
            }
        }
    }
}
Also used : CGOptions(soot.options.CGOptions)

Aggregations

CGOptions (soot.options.CGOptions)4 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 ArrayType (soot.ArrayType)1 Body (soot.Body)1 BooleanType (soot.BooleanType)1 PrimType (soot.PrimType)1 RefLikeType (soot.RefLikeType)1 RefType (soot.RefType)1 SootClass (soot.SootClass)1 SootMethod (soot.SootMethod)1 Type (soot.Type)1 VoidType (soot.VoidType)1 JimpleBody (soot.jimple.JimpleBody)1