Search in sources :

Example 56 with SootClass

use of soot.SootClass in project soot by Sable.

the class ClassResolver method createClassDecl.

/**
 * Class Declaration Creation
 */
private void createClassDecl(polyglot.ast.ClassDecl cDecl) {
    // add outer class tag if neccessary (if class is not top-level)
    if (!cDecl.type().isTopLevel()) {
        SootClass outerClass = ((soot.RefType) Util.getSootType(cDecl.type().outer())).getSootClass();
        if (InitialResolver.v().getInnerClassInfoMap() == null) {
            InitialResolver.v().setInnerClassInfoMap(new HashMap<SootClass, InnerClassInfo>());
        }
        InitialResolver.v().getInnerClassInfoMap().put(sootClass, new InnerClassInfo(outerClass, cDecl.name(), InnerClassInfo.NESTED));
        sootClass.setOuterClass(outerClass);
    }
    // modifiers
    polyglot.types.Flags flags = cDecl.flags();
    addModifiers(flags, cDecl);
    // super class
    if (cDecl.superClass() == null) {
        soot.SootClass superClass = soot.Scene.v().getSootClass("java.lang.Object");
        sootClass.setSuperclass(superClass);
    } else {
        sootClass.setSuperclass(((soot.RefType) Util.getSootType(cDecl.superClass().type())).getSootClass());
        if (((polyglot.types.ClassType) cDecl.superClass().type()).isNested()) {
            polyglot.types.ClassType superType = (polyglot.types.ClassType) cDecl.superClass().type();
            // add inner clas tag
            Util.addInnerClassTag(sootClass, sootClass.getName(), ((soot.RefType) Util.getSootType(superType.outer())).toString(), superType.name(), Util.getModifier(superType.flags()));
        }
    }
    // implements
    Iterator interfacesIt = cDecl.interfaces().iterator();
    while (interfacesIt.hasNext()) {
        polyglot.ast.TypeNode next = (polyglot.ast.TypeNode) interfacesIt.next();
        sootClass.addInterface(((soot.RefType) Util.getSootType(next.type())).getSootClass());
    }
    findReferences(cDecl);
    createClassBody(cDecl.body());
    // handle initialization of fields
    // static fields init in clinit
    // other fields init in init
    handleFieldInits();
    if ((staticFieldInits != null) || (staticInitializerBlocks != null)) {
        soot.SootMethod clinitMethod;
        if (!sootClass.declaresMethod("<clinit>", new ArrayList(), soot.VoidType.v())) {
            clinitMethod = Scene.v().makeSootMethod("<clinit>", new ArrayList(), soot.VoidType.v(), soot.Modifier.STATIC, new ArrayList<SootClass>());
            sootClass.addMethod(clinitMethod);
            PolyglotMethodSource mSource = new PolyglotMethodSource();
            mSource.setJBB(InitialResolver.v().getJBBFactory().createJimpleBodyBuilder());
            clinitMethod.setSource(mSource);
        } else {
            clinitMethod = sootClass.getMethod("<clinit>", new ArrayList(), soot.VoidType.v());
        }
        ((PolyglotMethodSource) clinitMethod.getSource()).setStaticFieldInits(staticFieldInits);
        ((PolyglotMethodSource) clinitMethod.getSource()).setStaticInitializerBlocks(staticInitializerBlocks);
    }
    // add final locals to local inner classes inits
    if (cDecl.type().isLocal()) {
        AnonLocalClassInfo info = InitialResolver.v().finalLocalInfo().get(new polyglot.util.IdentityKey(cDecl.type()));
        ArrayList<SootField> finalsList = addFinalLocals(cDecl.body(), info.finalLocalsAvail(), cDecl.type(), info);
        Iterator it = sootClass.getMethods().iterator();
        while (it.hasNext()) {
            soot.SootMethod meth = (soot.SootMethod) it.next();
            if (meth.getName().equals("<init>")) {
                ((PolyglotMethodSource) meth.getSource()).setFinalsList(finalsList);
            }
        }
        if (!info.inStaticMethod()) {
            polyglot.types.ClassType outerType = cDecl.type().outer();
            addOuterClassThisRefToInit(outerType);
            addOuterClassThisRefField(outerType);
        }
    } else // and out class field ref (only for non-static inner classes
    if (cDecl.type().isNested() && !cDecl.flags().isStatic()) {
        polyglot.types.ClassType outerType = cDecl.type().outer();
        addOuterClassThisRefToInit(outerType);
        addOuterClassThisRefField(outerType);
    }
    Util.addLnPosTags(sootClass, cDecl.position());
}
Also used : ArrayList(java.util.ArrayList) IdentityKey(polyglot.util.IdentityKey) SootClass(soot.SootClass) SootClass(soot.SootClass) RefType(soot.RefType) SootMethod(soot.SootMethod) Iterator(java.util.Iterator) SootMethod(soot.SootMethod) SootField(soot.SootField)

Example 57 with SootClass

use of soot.SootClass in project soot by Sable.

the class ClassResolver method handleInnerClassTags.

private void handleInnerClassTags(polyglot.ast.ClassBody classBody) {
    // if this class is an inner class add self
    if ((InitialResolver.v().getInnerClassInfoMap() != null) && (InitialResolver.v().getInnerClassInfoMap().containsKey(sootClass))) {
        // hasTag("OuterClassTag")){
        InnerClassInfo tag = InitialResolver.v().getInnerClassInfoMap().get(sootClass);
        Util.addInnerClassTag(sootClass, sootClass.getName(), tag.getInnerType() == InnerClassInfo.ANON ? null : tag.getOuterClass().getName(), tag.getInnerType() == InnerClassInfo.ANON ? null : tag.getSimpleName(), soot.Modifier.isInterface(tag.getOuterClass().getModifiers()) ? soot.Modifier.STATIC | soot.Modifier.PUBLIC : sootClass.getModifiers());
        // if this class is an inner class and enclosing class is also
        // an inner class add enclsing class
        SootClass outerClass = tag.getOuterClass();
        while (InitialResolver.v().getInnerClassInfoMap().containsKey(outerClass)) {
            InnerClassInfo tag2 = InitialResolver.v().getInnerClassInfoMap().get(outerClass);
            Util.addInnerClassTag(sootClass, outerClass.getName(), tag2.getInnerType() == InnerClassInfo.ANON ? null : tag2.getOuterClass().getName(), tag2.getInnerType() == InnerClassInfo.ANON ? null : tag2.getSimpleName(), tag2.getInnerType() == InnerClassInfo.ANON && soot.Modifier.isInterface(tag2.getOuterClass().getModifiers()) ? soot.Modifier.STATIC | soot.Modifier.PUBLIC : outerClass.getModifiers());
            outerClass = tag2.getOuterClass();
        }
    }
}
Also used : SootClass(soot.SootClass)

Example 58 with SootClass

use of soot.SootClass in project soot by Sable.

the class ClassResolver method createConstructorDecl.

/**
 * Constructor Declaration Creation
 */
private void createConstructorDecl(polyglot.ast.ConstructorDecl constructor) {
    String name = "<init>";
    ArrayList parameters = createParameters(constructor);
    ArrayList<SootClass> exceptions = createExceptions(constructor);
    soot.SootMethod sootMethod = createSootConstructor(name, constructor.flags(), parameters, exceptions);
    finishProcedure(constructor, sootMethod);
}
Also used : SootMethod(soot.SootMethod) ArrayList(java.util.ArrayList) SootClass(soot.SootClass)

Example 59 with SootClass

use of soot.SootClass in project soot by Sable.

the class ClassResolver method createMethodDecl.

/**
 * Method Declaration Creation
 */
private void createMethodDecl(polyglot.ast.MethodDecl method) {
    String name = createName(method);
    // parameters
    ArrayList parameters = createParameters(method);
    // exceptions
    ArrayList<SootClass> exceptions = createExceptions(method);
    soot.SootMethod sootMethod = createSootMethod(name, method.flags(), method.returnType().type(), parameters, exceptions);
    finishProcedure(method, sootMethod);
}
Also used : SootMethod(soot.SootMethod) ArrayList(java.util.ArrayList) SootClass(soot.SootClass)

Example 60 with SootClass

use of soot.SootClass in project soot by Sable.

the class ClassResolver method getSpecialInterfaceAnonClass.

private soot.SootClass getSpecialInterfaceAnonClass(soot.SootClass addToClass) {
    // interface
    if ((InitialResolver.v().specialAnonMap() != null) && (InitialResolver.v().specialAnonMap().containsKey(addToClass))) {
        return InitialResolver.v().specialAnonMap().get(addToClass);
    } else {
        String specialClassName = addToClass.getName() + "$" + InitialResolver.v().getNextAnonNum();
        // add class to scene and other maps and lists as needed
        soot.SootClass specialClass = new soot.SootClass(specialClassName);
        soot.Scene.v().addClass(specialClass);
        specialClass.setApplicationClass();
        specialClass.addTag(new soot.tagkit.SyntheticTag());
        specialClass.setSuperclass(soot.Scene.v().getSootClass("java.lang.Object"));
        Util.addInnerClassTag(addToClass, specialClass.getName(), addToClass.getName(), null, soot.Modifier.STATIC);
        Util.addInnerClassTag(specialClass, specialClass.getName(), addToClass.getName(), null, soot.Modifier.STATIC);
        InitialResolver.v().addNameToAST(specialClassName);
        references.add(RefType.v(specialClassName));
        if (InitialResolver.v().specialAnonMap() == null) {
            InitialResolver.v().setSpecialAnonMap(new HashMap<SootClass, SootClass>());
        }
        InitialResolver.v().specialAnonMap().put(addToClass, specialClass);
        return specialClass;
    }
}
Also used : SootClass(soot.SootClass) SootClass(soot.SootClass)

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