Search in sources :

Example 71 with SootClass

use of soot.SootClass in project soot by Sable.

the class SootASMClassWriterTest method testGetCommonSuperClassTransitive.

@Test
public void testGetCommonSuperClassTransitive() {
    SootClass sc11 = mockClass("AA");
    SootClass sc21 = mockClass("BB");
    when(sc11.getSuperclass()).thenReturn(commonSuperClass);
    when(sc21.getSuperclass()).thenReturn(commonSuperClass);
    when(sc11.getSuperclassUnsafe()).thenReturn(commonSuperClass);
    when(sc21.getSuperclassUnsafe()).thenReturn(commonSuperClass);
    when(sc1.getSuperclass()).thenReturn(sc11);
    when(sc2.getSuperclass()).thenReturn(sc21);
    when(sc1.getSuperclassUnsafe()).thenReturn(sc11);
    when(sc2.getSuperclassUnsafe()).thenReturn(sc21);
    assertEquals("C", cw.getCommonSuperClass("A", "B"));
}
Also used : SootClass(soot.SootClass) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 72 with SootClass

use of soot.SootClass in project soot by Sable.

the class SootASMClassWriterTest method testGetCommonSuperClassPhantomClass.

@Test
public void testGetCommonSuperClassPhantomClass() {
    SootClass sc11 = mockClass("AA");
    when(sc11.isPhantomClass()).thenReturn(true);
    when(sc11.hasSuperclass()).thenReturn(false);
    when(sc11.getSuperclass()).thenReturn(null);
    when(sc11.getSuperclassUnsafe()).thenReturn(null);
    when(sc1.getSuperclass()).thenReturn(sc11);
    when(sc2.getSuperclass()).thenReturn(commonSuperClass);
    when(sc1.getSuperclassUnsafe()).thenReturn(sc11);
    when(sc2.getSuperclassUnsafe()).thenReturn(commonSuperClass);
    assertEquals("java/lang/Object", cw.getCommonSuperClass("A", "B"));
}
Also used : SootClass(soot.SootClass) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 73 with SootClass

use of soot.SootClass in project soot by Sable.

the class CallGraphExample method main.

public static void main(String[] args) {
    List<String> argsList = new ArrayList<String>(Arrays.asList(args));
    argsList.addAll(Arrays.asList(new String[] { "-w", "-main-class", // main-class
    "testers.CallGraphs", // argument classes
    "testers.CallGraphs", // 
    "testers.A" }));
    PackManager.v().getPack("wjtp").add(new Transform("wjtp.myTrans", new SceneTransformer() {

        @Override
        protected void internalTransform(String phaseName, Map options) {
            CHATransformer.v().transform();
            SootClass a = Scene.v().getSootClass("testers.A");
            SootMethod src = Scene.v().getMainClass().getMethodByName("doStuff");
            CallGraph cg = Scene.v().getCallGraph();
            Iterator<MethodOrMethodContext> targets = new Targets(cg.edgesOutOf(src));
            while (targets.hasNext()) {
                SootMethod tgt = (SootMethod) targets.next();
                System.out.println(src + " may call " + tgt);
            }
        }
    }));
    args = argsList.toArray(new String[0]);
    soot.Main.main(args);
}
Also used : CallGraph(soot.jimple.toolkits.callgraph.CallGraph) ArrayList(java.util.ArrayList) SootMethod(soot.SootMethod) Targets(soot.jimple.toolkits.callgraph.Targets) Transform(soot.Transform) SootClass(soot.SootClass) MethodOrMethodContext(soot.MethodOrMethodContext) Map(java.util.Map) SceneTransformer(soot.SceneTransformer)

Example 74 with SootClass

use of soot.SootClass in project soot by Sable.

the class Foonalasys method loadClass.

/**
 * Loads the named class into the Soot scene,
 *  marks it as an application class, and generates bodies
 *  for all of its concrete methods.
 *  @param name the fully qualified name of the class to be loaded.
 */
public static void loadClass(String name) {
    SootClass c = Scene.v().loadClassAndSupport(name);
    c.setApplicationClass();
    Iterator mi = c.getMethods().iterator();
    while (mi.hasNext()) {
        SootMethod sm = (SootMethod) mi.next();
        if (sm.isConcrete()) {
            sm.retrieveActiveBody();
        }
    }
}
Also used : Iterator(java.util.Iterator) SootMethod(soot.SootMethod) SootClass(soot.SootClass)

Example 75 with SootClass

use of soot.SootClass in project soot by Sable.

the class DexMethod method getThrownExceptions.

protected List<SootClass> getThrownExceptions(final Method method) {
    // the following snippet retrieves all exceptions that this method
    // throws by analyzing its annotations
    List<SootClass> thrownExceptions = new ArrayList<SootClass>();
    for (Annotation a : method.getAnnotations()) {
        Type atype = DexType.toSoot(a.getType());
        String atypes = atype.toString();
        if (!(atypes.equals("dalvik.annotation.Throws")))
            continue;
        for (AnnotationElement ae : a.getElements()) {
            EncodedValue ev = ae.getValue();
            if (ev instanceof ArrayEncodedValue) {
                for (EncodedValue evSub : ((ArrayEncodedValue) ev).getValue()) {
                    if (evSub instanceof TypeEncodedValue) {
                        TypeEncodedValue valueType = (TypeEncodedValue) evSub;
                        String exceptionName = valueType.getValue();
                        String dottedName = Util.dottedClassName(exceptionName);
                        thrownExceptions.add(SootResolver.v().makeClassRef(dottedName));
                    }
                }
            }
        }
    }
    return thrownExceptions;
}
Also used : EncodedValue(org.jf.dexlib2.iface.value.EncodedValue) TypeEncodedValue(org.jf.dexlib2.iface.value.TypeEncodedValue) ArrayEncodedValue(org.jf.dexlib2.iface.value.ArrayEncodedValue) Type(soot.Type) TypeEncodedValue(org.jf.dexlib2.iface.value.TypeEncodedValue) AnnotationElement(org.jf.dexlib2.iface.AnnotationElement) ArrayList(java.util.ArrayList) ArrayEncodedValue(org.jf.dexlib2.iface.value.ArrayEncodedValue) SootClass(soot.SootClass) Annotation(org.jf.dexlib2.iface.Annotation)

Aggregations

SootClass (soot.SootClass)194 SootMethod (soot.SootMethod)99 RefType (soot.RefType)69 ArrayList (java.util.ArrayList)60 Type (soot.Type)57 VoidType (soot.VoidType)33 ArrayType (soot.ArrayType)32 Iterator (java.util.Iterator)29 BooleanType (soot.BooleanType)29 DoubleType (soot.DoubleType)29 LongType (soot.LongType)29 Value (soot.Value)29 FloatType (soot.FloatType)28 Local (soot.Local)27 SootField (soot.SootField)27 List (java.util.List)26 CharType (soot.CharType)26 IntType (soot.IntType)26 ByteType (soot.ByteType)25 PrimType (soot.PrimType)23