Search in sources :

Example 11 with PrimType

use of soot.PrimType in project soot by Sable.

the class SuperFirstStmtHandler method createStmtAccordingToType.

public AugmentedStmt createStmtAccordingToType(Type tempType, Value tempVal, Local newLocal, SootMethodRef getMethodRef) {
    if (tempType instanceof RefType) {
        return createAugmentedStmtToAdd(newLocal, getMethodRef, tempVal);
    } else if (tempType instanceof PrimType) {
        // The value is a primitive type
        // create wrapper object new Integer(tempVal)
        PrimType t = (PrimType) tempType;
        // create ArgList to be sent to DNewInvokeExpr constructor
        ArrayList argList = new ArrayList();
        argList.add(tempVal);
        // LongType, ShortType
        if (t == BooleanType.v()) {
            // create TypeList to be sent to makeMethodRef
            ArrayList typeList = new ArrayList();
            typeList.add(IntType.v());
            DNewInvokeExpr argForStore = new DNewInvokeExpr(RefType.v("java.lang.Boolean"), makeMethodRef("Boolean", typeList), argList);
            return createAugmentedStmtToAdd(newLocal, getMethodRef, argForStore);
        } else if (t == ByteType.v()) {
            // create TypeList to be sent to makeMethodRef
            ArrayList typeList = new ArrayList();
            typeList.add(ByteType.v());
            DNewInvokeExpr argForStore = new DNewInvokeExpr(RefType.v("java.lang.Byte"), makeMethodRef("Byte", typeList), argList);
            return createAugmentedStmtToAdd(newLocal, getMethodRef, argForStore);
        } else if (t == CharType.v()) {
            // create TypeList to be sent to makeMethodRef
            ArrayList typeList = new ArrayList();
            typeList.add(CharType.v());
            DNewInvokeExpr argForStore = new DNewInvokeExpr(RefType.v("java.lang.Character"), makeMethodRef("Character", typeList), argList);
            return createAugmentedStmtToAdd(newLocal, getMethodRef, argForStore);
        } else if (t == DoubleType.v()) {
            // create TypeList to be sent to makeMethodRef
            ArrayList typeList = new ArrayList();
            typeList.add(DoubleType.v());
            DNewInvokeExpr argForStore = new DNewInvokeExpr(RefType.v("java.lang.Double"), makeMethodRef("Double", typeList), argList);
            return createAugmentedStmtToAdd(newLocal, getMethodRef, argForStore);
        } else if (t == FloatType.v()) {
            // create TypeList to be sent to makeMethodRef
            ArrayList typeList = new ArrayList();
            typeList.add(FloatType.v());
            DNewInvokeExpr argForStore = new DNewInvokeExpr(RefType.v("java.lang.Float"), makeMethodRef("Float", typeList), argList);
            return createAugmentedStmtToAdd(newLocal, getMethodRef, argForStore);
        } else if (t == IntType.v()) {
            // create TypeList to be sent to makeMethodRef
            ArrayList typeList = new ArrayList();
            typeList.add(IntType.v());
            DNewInvokeExpr argForStore = new DNewInvokeExpr(RefType.v("java.lang.Integer"), makeMethodRef("Integer", typeList), argList);
            return createAugmentedStmtToAdd(newLocal, getMethodRef, argForStore);
        } else if (t == LongType.v()) {
            // create TypeList to be sent to makeMethodRef
            ArrayList typeList = new ArrayList();
            typeList.add(LongType.v());
            DNewInvokeExpr argForStore = new DNewInvokeExpr(RefType.v("java.lang.Long"), makeMethodRef("Long", typeList), argList);
            return createAugmentedStmtToAdd(newLocal, getMethodRef, argForStore);
        } else if (t == ShortType.v()) {
            // create TypeList to be sent to makeMethodRef
            ArrayList typeList = new ArrayList();
            typeList.add(ShortType.v());
            DNewInvokeExpr argForStore = new DNewInvokeExpr(RefType.v("java.lang.Short"), makeMethodRef("Short", typeList), argList);
            return createAugmentedStmtToAdd(newLocal, getMethodRef, argForStore);
        } else {
            throw new DecompilationException("UNHANDLED PRIMTYPE:" + tempType);
        }
    } else // end of primitivetypes
    {
        throw new DecompilationException("The type:" + tempType + " is neither a reftype or a primtype");
    }
}
Also used : RefType(soot.RefType) DNewInvokeExpr(soot.dava.internal.javaRep.DNewInvokeExpr) ArrayList(java.util.ArrayList) PrimType(soot.PrimType) DecompilationException(soot.dava.DecompilationException)

Example 12 with PrimType

use of soot.PrimType in project soot by Sable.

the class BadFields method handleClass.

private void handleClass(SootClass cl) {
    for (Iterator<SootField> fIt = cl.getFields().iterator(); fIt.hasNext(); ) {
        final SootField f = fIt.next();
        if (!f.isStatic())
            continue;
        String typeName = f.getType().toString();
        if (typeName.equals("java.lang.Class"))
            continue;
        if (f.isFinal()) {
            if (f.getType() instanceof PrimType)
                continue;
            if (typeName.equals("java.io.PrintStream"))
                continue;
            if (typeName.equals("java.lang.String"))
                continue;
            if (typeName.equals("java.lang.Object"))
                continue;
            if (typeName.equals("java.lang.Integer"))
                continue;
            if (typeName.equals("java.lang.Boolean"))
                continue;
        }
        warn("Bad field " + f);
    }
}
Also used : PrimType(soot.PrimType) SootField(soot.SootField)

Example 13 with PrimType

use of soot.PrimType in project soot by Sable.

the class DexlibWrapper method initialize.

public void initialize() {
    // resolve classes in dex files
    for (DexBackedDexFile dexFile : dexFiles) {
        for (ClassDef defItem : dexFile.getClasses()) {
            String forClassName = Util.dottedClassName(defItem.getType());
            classesToDefItems.put(forClassName, new ClassInformation(dexFile, defItem));
        }
    }
    // produce an error during type resolution.
    for (DexBackedDexFile dexFile : dexFiles) {
        for (int i = 0; i < dexFile.getTypeCount(); i++) {
            String t = dexFile.getType(i);
            Type st = DexType.toSoot(t);
            if (st instanceof ArrayType) {
                st = ((ArrayType) st).baseType;
            }
            String sootTypeName = st.toString();
            if (!Scene.v().containsClass(sootTypeName)) {
                if (st instanceof PrimType || st instanceof VoidType || systemAnnotationNames.contains(sootTypeName)) {
                    /*
						 * dex files contain references to the Type IDs of the
						 * system annotations. They are only visible to the
						 * Dalvik VM (for reflection, see
						 * vm/reflect/Annotations.cpp), and not to the user - so
						 * we do not want them to be resolved.
						 */
                    continue;
                }
                SootResolver.v().makeClassRef(sootTypeName);
            }
            SootResolver.v().resolveClass(sootTypeName, SootClass.SIGNATURES);
        }
    }
}
Also used : ArrayType(soot.ArrayType) VoidType(soot.VoidType) DexBackedDexFile(org.jf.dexlib2.dexbacked.DexBackedDexFile) ClassDef(org.jf.dexlib2.iface.ClassDef) ArrayType(soot.ArrayType) Type(soot.Type) PrimType(soot.PrimType) VoidType(soot.VoidType) PrimType(soot.PrimType)

Example 14 with PrimType

use of soot.PrimType in project soot by Sable.

the class TypeCastingError method inASTStatementSequenceNode.

public void inASTStatementSequenceNode(ASTStatementSequenceNode node) {
    for (AugmentedStmt as : node.getStatements()) {
        Stmt s = as.get_Stmt();
        if (!(s instanceof DefinitionStmt))
            continue;
        DefinitionStmt ds = (DefinitionStmt) s;
        if (myDebug)
            System.out.println("Definition stmt" + ds);
        ValueBox rightBox = ds.getRightOpBox();
        ValueBox leftBox = ds.getLeftOpBox();
        Value right = rightBox.getValue();
        Value left = leftBox.getValue();
        if (!(left.getType() instanceof PrimType && right.getType() instanceof PrimType)) {
            // only interested in prim type casting errors
            if (myDebug)
                System.out.println("\tDefinition stmt does not contain prims no need to modify");
            continue;
        }
        Type leftType = left.getType();
        Type rightType = right.getType();
        if (myDebug)
            System.out.println("Left type is: " + leftType);
        if (myDebug)
            System.out.println("Right type is: " + rightType);
        if (leftType.equals(rightType)) {
            if (myDebug)
                System.out.println("\tTypes are the same");
            if (myDebug)
                System.out.println("Right value is of instance" + right.getClass());
        }
        if (!leftType.equals(rightType)) {
            if (myDebug)
                System.out.println("\tDefinition stmt has to be modified");
            /*
				 * byte  	 Byte-length integer  	8-bit two's complement
				 * short 	Short integer 	16-bit two's complement
				 * int 	Integer 	32-bit two's complement
				 * long 	Long integer 	64-bit two's complement
				 * float 	Single-precision floating point 	32-bit IEEE 754
				 * double Double-precision floating point  	64-bit IEEE 754 	
				 */
            if (leftType instanceof ByteType && (rightType instanceof DoubleType || rightType instanceof FloatType || rightType instanceof IntType || rightType instanceof LongType || rightType instanceof ShortType)) {
                if (DEBUG)
                    System.out.println("Explicit casting to BYTE required");
                rightBox.setValue(new GCastExpr(right, ByteType.v()));
                if (DEBUG)
                    System.out.println("New right expr is " + rightBox.getValue().toString());
                continue;
            }
            if (leftType instanceof ShortType && (rightType instanceof DoubleType || rightType instanceof FloatType || rightType instanceof IntType || rightType instanceof LongType)) {
                if (DEBUG)
                    System.out.println("Explicit casting to SHORT required");
                rightBox.setValue(new GCastExpr(right, ShortType.v()));
                if (DEBUG)
                    System.out.println("New right expr is " + rightBox.getValue().toString());
                continue;
            }
            if (leftType instanceof IntType && (rightType instanceof DoubleType || rightType instanceof FloatType || rightType instanceof LongType)) {
                if (myDebug)
                    System.out.println("Explicit casting to INT required");
                rightBox.setValue(new GCastExpr(right, IntType.v()));
                if (myDebug)
                    System.out.println("New right expr is " + rightBox.getValue().toString());
                continue;
            }
            if (leftType instanceof LongType && (rightType instanceof DoubleType || rightType instanceof FloatType)) {
                if (DEBUG)
                    System.out.println("Explicit casting to LONG required");
                rightBox.setValue(new GCastExpr(right, LongType.v()));
                if (DEBUG)
                    System.out.println("New right expr is " + rightBox.getValue().toString());
                continue;
            }
            if (leftType instanceof FloatType && rightType instanceof DoubleType) {
                if (DEBUG)
                    System.out.println("Explicit casting to FLOAT required");
                rightBox.setValue(new GCastExpr(right, FloatType.v()));
                if (DEBUG)
                    System.out.println("New right expr is " + rightBox.getValue().toString());
                continue;
            }
        }
    }
}
Also used : LongType(soot.LongType) ShortType(soot.ShortType) ByteType(soot.ByteType) AugmentedStmt(soot.dava.internal.asg.AugmentedStmt) Stmt(soot.jimple.Stmt) AugmentedStmt(soot.dava.internal.asg.AugmentedStmt) DefinitionStmt(soot.jimple.DefinitionStmt) FloatType(soot.FloatType) IntType(soot.IntType) ByteType(soot.ByteType) DoubleType(soot.DoubleType) FloatType(soot.FloatType) IntType(soot.IntType) Type(soot.Type) PrimType(soot.PrimType) ShortType(soot.ShortType) LongType(soot.LongType) ValueBox(soot.ValueBox) DoubleType(soot.DoubleType) Value(soot.Value) PrimType(soot.PrimType) GCastExpr(soot.grimp.internal.GCastExpr) DefinitionStmt(soot.jimple.DefinitionStmt)

Example 15 with PrimType

use of soot.PrimType in project soot by Sable.

the class ReflectiveCallsInliner method unboxParameter.

/**
 * Auto-unboxes an argument array.
 *
 * @param argsArrayLocal
 *            a local holding the argument Object[] array
 * @param paramIndex
 *            the index of the parameter to unbox
 * @param paramType
 *            the (target) type of the parameter
 * @param newUnits
 *            the Unit chain to which the unboxing code will be appended
 * @param localGen
 *            a {@link LocalGenerator} for the body holding the units
 */
private void unboxParameter(Local argsArrayLocal, int paramIndex, Local[] paramLocals, Type paramType, Chain<Unit> newUnits, LocalGenerator localGen) {
    ArrayRef arrayRef = Jimple.v().newArrayRef(argsArrayLocal, IntConstant.v(paramIndex));
    AssignStmt assignStmt;
    if (paramType instanceof PrimType) {
        PrimType primType = (PrimType) paramType;
        // Unbox the value if needed
        RefType boxedType = primType.boxedType();
        SootMethodRef ref = Scene.v().makeMethodRef(boxedType.getSootClass(), paramType + "Value", Collections.<Type>emptyList(), paramType, false);
        Local boxedLocal = localGen.generateLocal(RefType.v("java.lang.Object"));
        AssignStmt arrayLoad = Jimple.v().newAssignStmt(boxedLocal, arrayRef);
        newUnits.add(arrayLoad);
        Local castedLocal = localGen.generateLocal(boxedType);
        AssignStmt cast = Jimple.v().newAssignStmt(castedLocal, Jimple.v().newCastExpr(boxedLocal, boxedType));
        newUnits.add(cast);
        VirtualInvokeExpr unboxInvokeExpr = Jimple.v().newVirtualInvokeExpr(castedLocal, ref);
        assignStmt = Jimple.v().newAssignStmt(paramLocals[paramIndex], unboxInvokeExpr);
    } else {
        Local boxedLocal = localGen.generateLocal(RefType.v("java.lang.Object"));
        AssignStmt arrayLoad = Jimple.v().newAssignStmt(boxedLocal, arrayRef);
        newUnits.add(arrayLoad);
        Local castedLocal = localGen.generateLocal(paramType);
        AssignStmt cast = Jimple.v().newAssignStmt(castedLocal, Jimple.v().newCastExpr(boxedLocal, paramType));
        newUnits.add(cast);
        assignStmt = Jimple.v().newAssignStmt(paramLocals[paramIndex], castedLocal);
    }
    newUnits.add(assignStmt);
}
Also used : ArrayRef(soot.jimple.ArrayRef) RefType(soot.RefType) SootMethodRef(soot.SootMethodRef) AssignStmt(soot.jimple.AssignStmt) PrimType(soot.PrimType) Local(soot.Local) VirtualInvokeExpr(soot.jimple.VirtualInvokeExpr)

Aggregations

PrimType (soot.PrimType)31 RefType (soot.RefType)15 ArrayList (java.util.ArrayList)12 Type (soot.Type)10 Value (soot.Value)10 DoubleType (soot.DoubleType)9 FloatType (soot.FloatType)9 IntType (soot.IntType)9 Local (soot.Local)9 LongType (soot.LongType)9 BooleanType (soot.BooleanType)8 SootClass (soot.SootClass)8 SootMethod (soot.SootMethod)8 ByteType (soot.ByteType)7 CharType (soot.CharType)7 ShortType (soot.ShortType)7 ArrayType (soot.ArrayType)6 VoidType (soot.VoidType)6 MethodVisitor (org.objectweb.asm.MethodVisitor)4 PointerType (org.robovm.compiler.llvm.PointerType)4