Package soot.jimple

Examples of soot.jimple.CastExpr


            Value lhs = ds.getLeftOp();
            Value rhs = ds.getRightOp();

            if (rhs instanceof CastExpr) {
              //un-box casted value
        CastExpr castExpr = (CastExpr) rhs;
              rhs = castExpr.getOp();
            }
           
            if ((lhs instanceof Local
                || (lhs instanceof FieldRef && this.localsAndFieldRefs.contains(new EquivalentValue(lhs))))
              && lhs.getType() instanceof RefLikeType) {
View Full Code Here


                            //                             r.setField(changeClass.getFieldByName(
                            //                                     r.getField().getName()));
                        }
                    } else if (value instanceof CastExpr) {
                        // Fix casts
                        CastExpr r = (CastExpr) value;

                        try {
                            if (object != analysis.getObject((Local) r.getOp())) {
                                continue;
                            }
                        } catch (Exception ex) {
                            if (_debug) {
                                System.out.println("Exception on cast = " + ex);
                            }

                            continue;
                        }

                        Type type = r.getType();

                        if (type instanceof RefType) {
                            SootClass refClass = ((RefType) type)
                                    .getSootClass();

                            if (refClass == oldClass) {
                                r.setCastType(RefType.v(newClass));

                                //    System.out.println("newValue = " +
                                //        box.getValue());
                                //                             } else if (refClass.getName().startsWith(
                                //                                     oldClass.getName())) {
                                //                                 SootClass changeClass =
                                //                                     _getInnerClassCopy(oldClass,
                                //                                             refClass, newClass);
                                //                                 r.setCastType(RefType.v(changeClass));
                            }
                        }

                        //     } else if (value instanceof ThisRef) {
                        //                         // Fix references to 'this'
                        //                         ThisRef r = (ThisRef)value;
                        //                         Type type = r.getType();
                        //                         if (type instanceof RefType &&
                        //                                 ((RefType)type).getSootClass() == oldClass) {
                        //                             box.setValue(Jimple.v().newThisRef(
                        //                                     RefType.v(newClass)));
                        //                         }
                        //                     } else if (value instanceof ParameterRef) {
                        //                         // Fix references to a parameter
                        //                         ParameterRef r = (ParameterRef)value;
                        //                         Type type = r.getType();
                        //                         if (type instanceof RefType &&
                        //                                 ((RefType)type).getSootClass() == oldClass) {
                        //                             box.setValue(Jimple.v().newParameterRef(
                        //                                     RefType.v(newClass), r.getIndex()));
                        //                         }
                    } else if (value instanceof InstanceInvokeExpr) {
                        // Fix up the method invokes.
                        InstanceInvokeExpr r = (InstanceInvokeExpr) value;

                        try {
                            if (object != analysis.getObject((Local) r
                                    .getBase())) {
                                //                                 System.out.println("object = " + object);
                                //                                 System.out.println("analysis object = " + analysis.getObject((Local)r.getBase()));
                                //                                 System.out.println("not equal!");
                                continue;
                            }
                        } catch (Exception ex) {
                            if (_debug) {
                                System.out.println("Exception on invoke = "
                                        + ex);
                            }

                            continue;
                        }

                        if (SootUtilities.derivesFrom(oldClass, r.getMethod()
                                .getDeclaringClass())) {
                            if (newClass.declaresMethod(r.getMethod()
                                    .getSubSignature())) {
                                SootMethod replacementMethod = newClass
                                        .getMethod(r.getMethod()
                                                .getSubSignature());
                                r.setMethodRef(replacementMethod.makeRef());
                            }

                            //                         } else if (r.getMethod().getDeclaringClass().getName().
                            //                                 startsWith(oldClass.getName())) {
                            //                             SootClass changeClass =
                            //                                 _getInnerClassCopy(oldClass,
                            //                                         r.getMethod().getDeclaringClass(),
                            //                                         newClass);
                            //                             r.setMethod(changeClass.getMethod(
                            //                                     r.getMethod().getSubSignature()));
                        }
                    } else if (value instanceof NewExpr) {
                        // Fix up the object creations.
                        NewExpr r = (NewExpr) value;

                        if (!(unit instanceof AssignStmt)) {
                            continue;
                        }

                        AssignStmt stmt = (AssignStmt) unit;

                        try {
                            if (object != analysis.getObject((Local) stmt
                                    .getLeftOp())) {
                                continue;
                            }
                        } catch (Exception ex) {
                            if (_debug) {
                                System.out.println("Exception on new = " + ex);
                            }

                            continue;
                        }

                        if (r.getBaseType().getSootClass() == oldClass) {
                            r.setBaseType(RefType.v(newClass));

                            //   System.out.println("newValue = " +
                            //           box.getValue());
                            //                         } else if (r.getBaseType().getSootClass().getName().
                            //                                 startsWith(oldClass.getName())) {
View Full Code Here

                            .hasNext();) {
                        ValueBox box = (ValueBox) boxes.next();
                        Value value = box.getValue();

                        if (value instanceof CastExpr) {
                            CastExpr expr = (CastExpr) value;
                            Type castType = expr.getCastType();

                            if (castType instanceof RefType) {
                                SootClass castClass = ((RefType) castType)
                                        .getSootClass();

                                if (castClass.isInterface()) {
                                    necessaryClasses.add(castClass);
                                } else {
                                    necessaryClasses
                                            .addAll(hierarchy
                                                    .getSuperclassesOfIncluding(castClass));
                                }

                                _addAllInterfaces(necessaryClasses, castClass);
                            }
                        } else if (value instanceof InstanceOfExpr) {
                            InstanceOfExpr expr = (InstanceOfExpr) value;
                            Type checkType = expr.getCheckType();

                            if (checkType instanceof RefType) {
                                SootClass checkClass = ((RefType) checkType)
                                        .getSootClass();
View Full Code Here

                // transformation.
                if (value instanceof CastExpr) {
                    // If the cast is to the same type as the
                    // operand already is, then replace with
                    // simple assignment.
                    CastExpr expr = (CastExpr) value;
                    Type castType = expr.getCastType();
                    Value op = expr.getOp();
                    Type opType = op.getType();

                    //                     // Skip locals that are unsafe.
                    //                     if (castType.equals(opType) &&
                    //                             !unsafeLocalSet.contains(op)) {
                    //                         box.setValue(op);
                    //                     }
                    if (unsafeLocalSet.contains(op)) {
                        continue;
                    }

                    Hierarchy hierarchy = Scene.v().getActiveHierarchy();

                    //   if (debug) System.out.println("checking cast in " + unit);
                    //                     if (debug) System.out.println("op = " + op);
                    //                     if (debug) System.out.println("opType = " + opType);
                    replaceCast(box, hierarchy, castType, op, opType, debug);
                } else if (value instanceof InstanceOfExpr) {
                    // If the operand of the expression is
                    // declared to be of a type that implies
                    // the instanceof is true, then replace
                    // with true.
                    InstanceOfExpr expr = (InstanceOfExpr) value;
                    Type checkType = expr.getCheckType();
                    Value op = expr.getOp();
                    Type opType = op.getType();

                    // Skip locals that are unsafe.
                    if (unsafeLocalSet.contains(op)) {
                        continue;
View Full Code Here

                //  System.out.println("arrayRef stmt = " + stmt);
                //                 System.out.println("right type = " + in.get(((ArrayRef)rightOp).getBase()));
                _updateTypeInAssignment(leftOp, in.get(((ArrayRef) rightOp)
                        .getBase()), out);
            } else if (rightOp instanceof CastExpr) {
                CastExpr castExpr = (CastExpr) rightOp;
                Type type = castExpr.getType();

                // FIXME: what if downcast???
                /*RefType tokenType =*/PtolemyUtilities.getBaseTokenType(type);

                //       System.out.println("castType = " + tokenType);
                //                 System.out.println("castOp = " + castExpr.getOp());
                //                 System.out.println("currentType = " + in.get(castExpr.getOp()));
                //if (tokenType != null) {
                _updateTypeInAssignment(leftOp, in.get(castExpr.getOp()), out);

                // } else {
                // Otherwise there is nothing to be done.
                //}
            } else if (rightOp instanceof Local) {
View Full Code Here

                        //                             //              box.getValue());
                        //                         }

                    } else if (value instanceof CastExpr) {
                        // Fix casts
                        CastExpr r = (CastExpr) value;
                        Type type = r.getType();

                        if (type instanceof RefType) {
                            SootClass refClass = ((RefType) type)
                                    .getSootClass();

                            if (refClass == oldClass) {
                                r.setCastType(RefType.v(newClass));

                                // System.out.println("newValue = " +
                                //        box.getValue());
                            } else if (refClass.getName().startsWith(
                                    oldClass.getName())) {
                                SootClass changeClass = _getInnerClassCopy(
                                        oldClass, refClass, newClass);
                                r.setCastType(RefType.v(changeClass));
                            }
                        }
                    } else if (value instanceof ThisRef) {
                        // Fix references to 'this'
                        ThisRef r = (ThisRef) value;
                        Type type = r.getType();

                        if (type instanceof RefType
                                && (((RefType) type).getSootClass() == oldClass)) {
                            box.setValue(Jimple.v().newThisRef(
                                    RefType.v(newClass)));
                        }
                    } else if (value instanceof ParameterRef) {
                        // Fix references to a parameter
                        ParameterRef r = (ParameterRef) value;
                        Type type = r.getType();

                        if (type instanceof RefType
                                && (((RefType) type).getSootClass() == oldClass)) {
                            box.setValue(Jimple.v().newParameterRef(
                                    RefType.v(newClass), r.getIndex()));
                        }
                    } else if (value instanceof InvokeExpr) {
                        // Fix up the method invokes.
                        InvokeExpr r = (InvokeExpr) value;
                        SootMethodRef methodRef = r.getMethodRef();
                        System.out.println("invoke = " + r);

                        List newParameterTypes = new LinkedList();
                        for (Iterator i = methodRef.parameterTypes().iterator(); i
                                .hasNext();) {
                            Type type = (Type) i.next();
                            if (type instanceof RefType
                                    && (((RefType) type).getSootClass() == oldClass)) {
                                System.out.println("matchedParameter = "
                                        + newClass);
                                newParameterTypes.add(RefType.v(newClass));
                            } else if (type instanceof RefType
                                    && (((RefType) type).getSootClass()
                                            .getName().startsWith(oldClass
                                            .getName()))) {
                                System.out.println("matchedParameter = "
                                        + newClass);
                                SootClass changeClass = _getInnerClassCopy(
                                        oldClass, ((RefType) type)
                                                .getSootClass(), newClass);
                                newParameterTypes.add(RefType.v(changeClass));
                            } else {
                                newParameterTypes.add(type);
                            }

                        }

                        Type newReturnType = methodRef.returnType();
                        if (newReturnType instanceof RefType
                                && (((RefType) newReturnType).getSootClass() == oldClass)) {
                            newReturnType = RefType.v(newClass);
                        }

                        // Update the parameter types and the return type.
                        methodRef = Scene.v().makeMethodRef(
                                methodRef.declaringClass(), methodRef.name(),
                                newParameterTypes, newReturnType,
                                methodRef.isStatic());
                        r.setMethodRef(methodRef);

                        if (methodRef.declaringClass() == oldClass) {
                            r.setMethodRef(Scene.v().makeMethodRef(newClass,
                                    methodRef.name(),
                                    methodRef.parameterTypes(),
                                    methodRef.returnType(),
                                    methodRef.isStatic()));
                            // System.out.println("newValue = " +
                            // box.getValue());
                        } else if (methodRef.declaringClass().getName()
                                .startsWith(oldClass.getName())) {
                            SootClass changeClass = _getInnerClassCopy(
                                    oldClass, methodRef.declaringClass(),
                                    newClass);
                            r.setMethodRef(Scene.v().makeMethodRef(changeClass,
                                    methodRef.name(),
                                    methodRef.parameterTypes(),
                                    methodRef.returnType(),
                                    methodRef.isStatic()));
                        }
                    } else if (value instanceof NewExpr) {
                        // Fix up the object creations.
                        NewExpr r = (NewExpr) value;

                        if (r.getBaseType().getSootClass() == oldClass) {
                            r.setBaseType(RefType.v(newClass));

                            //   System.out.println("newValue = " +
                            //           box.getValue());
                        } else if (r.getBaseType().getSootClass().getName()
                                .startsWith(oldClass.getName())) {
                            SootClass changeClass = _getInnerClassCopy(
                                    oldClass, r.getBaseType().getSootClass(),
                                    newClass);
                            r.setBaseType(RefType.v(changeClass));
                        }
                    }

                    //    System.out.println("value = " + value);
                    //   System.out.println("class = " +
View Full Code Here

                if (value instanceof CastExpr) {
                    // If the cast is to the same type as the
                    // operand already is, then replace with
                    // simple assignment.
                    CastExpr expr = (CastExpr) value;
                    Type castType = expr.getCastType();
                    Value op = expr.getOp();

                    if (!PtolemyUtilities.isTokenType(op.getType())) {
                        continue;
                    }

                    // Use the token type inference to get the actual
                    // type of the argument.
                    ptolemy.data.type.Type type = tokenTypes.getTypeOfBefore(
                            (Local) op, unit);

                    if (debug) {
                        System.out.println("checking cast in " + unit);
                    }

                    if (debug) {
                        System.out.println("op = " + op);
                    }

                    if (debug) {
                        System.out.println("type = " + type);
                    }

                    // Don't try to replace non-instantiable types, since they
                    // might be more refined later.
                    // General, is unfortuantely, considered instantiable.
                    if (type.equals(BaseType.UNKNOWN) //!type.isInstantiable() ||
                            || type.equals(BaseType.GENERAL)) {
                        continue;
                    }

                    Type opType = PtolemyUtilities
                            .getSootTypeForTokenType(type);

                    //                     // Skip locals that are unsafe.
                    //                     if (castType.equals(opType) &&
                    //                             !unsafeLocalSet.contains(op)) {
                    //                         box.setValue(op);
                    //                     }
                    if (unsafeLocalSet.contains(op)) {
                        continue;
                    }

                    Hierarchy hierarchy = Scene.v().getActiveHierarchy();

                    if (debug) {
                        System.out.println("opType = " + opType);
                    }

                    CastAndInstanceofEliminator.replaceCast(box, hierarchy,
                            castType, op, opType, debug);
                } else if (value instanceof InstanceOfExpr) {
                    // If the operand of the expression is
                    // declared to be of a type that implies
                    // the instanceof is true, then replace
                    // with true.
                    InstanceOfExpr expr = (InstanceOfExpr) value;
                    Type checkType = expr.getCheckType();
                    Value op = expr.getOp();

                    if (!PtolemyUtilities.isTokenType(op.getType())) {
                        continue;
                    }
View Full Code Here

            //                     new VariableTerm(arrayType, value));
            //             InequalityTerm returnTypeTerm = (InequalityTerm)
            //                 arrayType.getElementTypeTerm();
            //             return returnTypeTerm;
        } else if (value instanceof CastExpr) {
            CastExpr castExpr = (CastExpr) value;

            // The return type will be the type
            // of the cast.
            InequalityTerm baseTerm = (InequalityTerm) objectToInequalityTerm
                    .get(castExpr.getOp());
            return baseTerm;
        } else if (value instanceof NewExpr) {
            NewExpr newExpr = (NewExpr) value;
            RefType type = newExpr.getBaseType();
            SootClass castClass = type.getSootClass();
View Full Code Here

                    if (_isPtolemyException(exceptionClass)) {
                        expr.setBaseType(RefType
                                .v(PtolemyUtilities.runtimeExceptionClass));
                    }
                } else if (value instanceof CastExpr) {
                    CastExpr expr = (CastExpr) value;
                    Type castType = expr.getCastType();

                    if (castType instanceof RefType
                            && _isPtolemyException(((RefType) castType)
                                    .getSootClass())) {
                        expr.setCastType(RefType
                                .v(PtolemyUtilities.runtimeExceptionClass));
                    }
                } else if (value instanceof SpecialInvokeExpr) {
                    // Fix the exception constructors.
                    SpecialInvokeExpr expr = (SpecialInvokeExpr) value;
                    SootClass exceptionClass = ((RefType) expr.getBase()
                            .getType()).getSootClass();

                    if (_isPtolemyException(exceptionClass)) {
                        Value foundArg = null;

                        for (Iterator args = expr.getArgs().iterator(); args
                                .hasNext();) {
                            Value arg = (Value) args.next();

                            if (arg.getType().equals(
                                    RefType.v(PtolemyUtilities.stringClass))) {
                                foundArg = arg;
                                break;
                            }
                        }

                        if ((foundArg == null) || _obfuscate) {
                            box
                                    .setValue(Jimple
                                            .v()
                                            .newSpecialInvokeExpr(
                                                    (Local) expr.getBase(),
                                                    PtolemyUtilities.runtimeExceptionConstructor
                                                            .makeRef(),
                                                    Collections.EMPTY_LIST));
                        } else {
                            box
                                    .setValue(Jimple
                                            .v()
                                            .newSpecialInvokeExpr(
                                                    (Local) expr.getBase(),
                                                    PtolemyUtilities.runtimeExceptionStringConstructor
                                                            .makeRef(),
                                                    foundArg));
                        }
                    }
                } else if (value instanceof VirtualInvokeExpr) {
                    VirtualInvokeExpr expr = (VirtualInvokeExpr) value;
                    Type exceptionType = expr.getBase().getType();

                    if (exceptionType instanceof RefType) {
                        SootClass exceptionClass = ((RefType) exceptionType)
                                .getSootClass();

                        if (_isPtolemyException(exceptionClass)) {
                            SootMethod method = expr.getMethod();

                            if (method.getName().equals("getMessage")) {
                                if (unit instanceof InvokeStmt) {
                                    body.getUnits().remove(unit);
                                } else {
View Full Code Here

TOP

Related Classes of soot.jimple.CastExpr

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.