Search in sources :

Example 11 with SootFieldRef

use of soot.SootFieldRef in project soot by Sable.

the class FieldRenamer method internalTransform.

protected void internalTransform(String phaseName, Map<String, String> options) {
    if (output) {
        if (rename_fields) {
            out.println("Transforming Field Names and Adding Opaque Predicates...");
        } else {
            out.println("Adding Opaques...");
        }
    }
    RefType boolRef = Scene.v().getRefType(booleanClassName);
    BodyBuilder.retrieveAllBodies();
    BodyBuilder.retrieveAllNames();
    for (SootClass sc : Scene.v().getApplicationClasses()) {
        String className = sc.getName();
        if (className.contains(".")) {
            className = className.substring(className.lastIndexOf(".") + 1, className.length());
        }
        oldToNewFieldNames.put(className, className);
        if (rename_fields) {
            if (output) {
                out.println("\tClassName: " + className);
            }
            // rename all the fields in the class
            for (SootField f : sc.getFields()) {
                int weight = soot.jbco.Main.getWeight(phaseName, f.getName());
                if (weight > 0) {
                    renameField(className, f);
                }
            }
        }
        // skip interfaces - they can only hold final fields
        if (sc.isInterface()) {
            continue;
        }
        // add one opaq predicate for true and one for false to each class
        String bool = "opPred1";
        Type t = Rand.getInt() % 2 == 0 ? BooleanType.v() : boolRef;
        while (oldToNewFieldNames.containsKey(bool)) {
            bool += "_";
        }
        SootField f = Scene.v().makeSootField(bool, t, Modifier.PUBLIC | Modifier.STATIC);
        renameField(className, f);
        opaquePreds1ByClass.put(sc, f);
        sc.addField(f);
        setBooleanTo(sc, f, true);
        bool = "opPred2";
        t = t == BooleanType.v() ? boolRef : BooleanType.v();
        while (oldToNewFieldNames.containsKey(bool)) {
            bool += "_";
        }
        f = Scene.v().makeSootField(bool, t, Modifier.PUBLIC | Modifier.STATIC);
        renameField(className, f);
        opaquePreds2ByClass.put(sc, f);
        sc.addField(f);
        if (t == boolRef) {
            setBooleanTo(sc, f, false);
        }
    }
    buildOpaquePairings();
    if (!rename_fields) {
        return;
    }
    if (output) {
        out.println("\r\tUpdating field references in bytecode");
    }
    for (SootClass sc : Scene.v().getApplicationClasses()) {
        for (SootMethod m : sc.getMethods()) {
            if (!m.isConcrete()) {
                continue;
            }
            if (!m.hasActiveBody()) {
                m.retrieveActiveBody();
            }
            for (Unit unit : m.getActiveBody().getUnits()) {
                for (ValueBox box : unit.getUseAndDefBoxes()) {
                    Value value = box.getValue();
                    if (value instanceof FieldRef) {
                        FieldRef fieldRef = (FieldRef) value;
                        SootFieldRef sootFieldRef = fieldRef.getFieldRef();
                        if (sootFieldRef.declaringClass().isLibraryClass()) {
                            continue;
                        }
                        String oldName = sootFieldRef.name();
                        String fullName = sootFieldRef.declaringClass().getName() + '.' + oldName;
                        String newName = oldToNewFieldNames.get(oldName);
                        if (newName == null || namesToNotRename.contains(fullName)) {
                            continue;
                        }
                        if (newName.equals(oldName)) {
                            System.out.println("Strange.. Should not find a field with the same old and new name.");
                        }
                        sootFieldRef = Scene.v().makeFieldRef(sootFieldRef.declaringClass(), newName, sootFieldRef.type(), sootFieldRef.isStatic());
                        fieldRef.setFieldRef(sootFieldRef);
                        try {
                            sootFieldRef.resolve();
                        } catch (Exception e) {
                            System.err.println("********ERROR Updating " + sootFieldRef.name() + " to " + newName);
                            System.err.println("Fields of " + sootFieldRef.declaringClass().getName() + ": " + sootFieldRef.declaringClass().getFields());
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
        }
    }
}
Also used : FieldRef(soot.jimple.FieldRef) SootFieldRef(soot.SootFieldRef) SootClass(soot.SootClass) Unit(soot.Unit) SootFieldRef(soot.SootFieldRef) RefType(soot.RefType) RefType(soot.RefType) BooleanType(soot.BooleanType) IntegerType(soot.IntegerType) Type(soot.Type) VoidType(soot.VoidType) ValueBox(soot.ValueBox) Value(soot.Value) SootMethod(soot.SootMethod) SootField(soot.SootField)

Example 12 with SootFieldRef

use of soot.SootFieldRef in project soot by Sable.

the class Walker method outASigFieldRef.

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));
}
Also used : SootFieldRef(soot.SootFieldRef)

Example 13 with SootFieldRef

use of soot.SootFieldRef in project soot by Sable.

the class Walker method outALocalFieldRef.

/*
	 * field_ref = {local} local_name dot field_signature | {sig}
	 * field_signature;
	 */
public void outALocalFieldRef(ALocalFieldRef node) {
    SootFieldRef field = (SootFieldRef) mProductions.removeLast();
    String local = (String) mProductions.removeLast();
    Local l = mLocals.get(local);
    if (l == null)
        throw new RuntimeException("did not find local: " + local);
    mProductions.addLast(Jimple.v().newInstanceFieldRef(l, field));
}
Also used : Local(soot.Local) SootFieldRef(soot.SootFieldRef)

Example 14 with SootFieldRef

use of soot.SootFieldRef in project soot by Sable.

the class Walker method outAFieldSignature.

/*
	 * field_signature = cmplt [class_name]:class_name [first]:colon type
	 * [field_name]:name cmpgt;
	 */
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);
}
Also used : RefType(soot.RefType) ShortType(soot.ShortType) BooleanType(soot.BooleanType) ByteType(soot.ByteType) Type(soot.Type) UnknownType(soot.UnknownType) DoubleType(soot.DoubleType) FloatType(soot.FloatType) IntType(soot.IntType) CharType(soot.CharType) LongType(soot.LongType) NullType(soot.NullType) ArrayType(soot.ArrayType) VoidType(soot.VoidType) SootClass(soot.SootClass) SootFieldRef(soot.SootFieldRef)

Aggregations

SootFieldRef (soot.SootFieldRef)14 RefType (soot.RefType)9 SootClass (soot.SootClass)9 Type (soot.Type)9 ArrayType (soot.ArrayType)8 BooleanType (soot.BooleanType)7 DoubleType (soot.DoubleType)7 FloatType (soot.FloatType)7 IntType (soot.IntType)7 LongType (soot.LongType)7 Value (soot.Value)7 ByteType (soot.ByteType)6 CharType (soot.CharType)6 ShortType (soot.ShortType)6 VoidType (soot.VoidType)6 InstanceFieldRef (soot.jimple.InstanceFieldRef)6 Local (soot.Local)5 SootMethodRef (soot.SootMethodRef)5 List (java.util.List)4 UnknownType (soot.UnknownType)4