@Override protected int getMinJavaVersion(SootMethod method) { final BafBody body = getBafBody(method); int minVersion = Options.java_version_1_1; for (Unit u : body.getUnits()) { if (u instanceof DynamicInvokeInst) { return Options.java_version_1_7; } if (u instanceof PushInst) { if (((PushInst) u).getConstant() instanceof ClassConstant) { minVersion = Options.java_version_1_5; } } } return minVersion; }
public void jimplify (DexBody body) { if(!(instruction instanceof Instruction21c)) throw new IllegalArgumentException("Expected Instruction21c but got: "+instruction.getClass()); ReferenceInstruction constClass = (ReferenceInstruction) this.instruction; TypeReference tidi = (TypeReference)(constClass.getReference()); String type = tidi.getType(); if (type.startsWith("L") && type.endsWith(";")) type = type.replaceAll("^L", "").replaceAll(";$", ""); int dest = ((OneRegisterInstruction) instruction).getRegisterA(); Constant cst = ClassConstant.v(type); assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), cst); setUnit(assign); addTags(assign); body.add(assign); if (IDalvikTyper.ENABLE_DVKTYPER) { Debug.printDbg(IDalvikTyper.DEBUG, "constraint: "+ assign); int op = (int)instruction.getOpcode().value; //DalvikTyper.v().captureAssign((JAssignStmt)assign, op); //TODO: classtype could be null! DalvikTyper.v().setType(assign.getLeftOpBox(), cst.getType(), false); } }
private Value toSootValue(Object val) throws AssertionError { Value v; if (val instanceof Integer) v = IntConstant.v((Integer) val); else if (val instanceof Float) v = FloatConstant.v((Float) val); else if (val instanceof Long) v = LongConstant.v((Long) val); else if (val instanceof Double) v = DoubleConstant.v((Double) val); else if (val instanceof String) v = StringConstant.v(val.toString()); else if (val instanceof org.objectweb.asm.Type) v = ClassConstant.v(((org.objectweb.asm.Type) val).getInternalName()); else if (val instanceof Handle) v = MethodHandle.v(toSootMethodRef((Handle) val), ((Handle)val).getTag()); else throw new AssertionError("Unknown constant type: " + val.getClass()); return v; }
/** * Add a class object. Needed for static fields. * @param sc SootClass. */ public static void addClassObjectToObjectMap(SootClass sc) { logger.log(Level.INFO, "Add object {0} to ObjectMap in method {1}", new Object[] {sc.getName(), b.getMethod().getName()} ); ArrayList<Type> parameterTypes = new ArrayList<Type>(); parameterTypes.add(RefType.v("java.lang.Object")); System.out.println("Adding class Object:" + sc.getName().replace(".", "/")); ClassConstant cc = ClassConstant.v(sc.getName().replace(".", "/")); System.out.println("Value: " + cc.value); Expr addObj = Jimple.v().newVirtualInvokeExpr( hs, Scene.v().makeMethodRef( Scene.v().getSootClass(HANDLE_CLASS), "addObjectToObjectMap", parameterTypes, VoidType.v(), false), ClassConstant.v(sc.getName().replace(".", "/"))); Unit assignExpr = Jimple.v().newInvokeStmt(addObj); unitStore_After.insertElement(unitStore_After.new Element(assignExpr, lastPos)); lastPos = assignExpr; }
public Set<ClassConstant> possibleClassConstants() { Set<ClassConstant> res = new HashSet<ClassConstant>(); for (AllocAndContext allocAndContext : this) { AllocNode n = allocAndContext.alloc; if( n instanceof ClassConstantNode ) { res.add( ((ClassConstantNode)n).getClassConstant() ); } else { return null; } } return res; }
public AllocNode makeClassConstantNode( ClassConstant cc ) { if( opts.types_for_sites() || opts.vta() ) return makeAllocNode( RefType.v( "java.lang.Class" ), RefType.v( "java.lang.Class" ), null ); ClassConstantNode ret = (ClassConstantNode) valToAllocNode.get(cc); if( ret == null ) { valToAllocNode.put(cc, ret = new ClassConstantNode(this, cc)); newAllocNodes.add( ret ); addNodeTag( ret, null ); } return ret; }
public Set<ClassConstant> possibleClassConstants() { final HashSet<ClassConstant> ret = new HashSet<ClassConstant>(); return this.forall( new P2SetVisitor() { public final void visit( Node n ) { if( n instanceof ClassConstantNode ) { ret.add( ((ClassConstantNode)n).getClassConstant() ); } else { returnValue = true; } }} ) ? null : ret; }
private void handleRefTypeAssignment(DefinitionStmt assignStmt, AnalysisInfo out) { Value left = assignStmt.getLeftOp(); Value right = assignStmt.getRightOp(); //unbox casted value if(right instanceof JCastExpr) { JCastExpr castExpr = (JCastExpr) right; right = castExpr.getOp(); } //if we have a definition (assignment) statement to a ref-like type, handle it, if ( isAlwaysNonNull(right) || right instanceof NewExpr || right instanceof NewArrayExpr || right instanceof NewMultiArrayExpr || right instanceof ThisRef || right instanceof StringConstant || right instanceof ClassConstant || right instanceof CaughtExceptionRef) { //if we assign new... or @this, the result is non-null out.put(left,NON_NULL); } else if(right==NullConstant.v()) { //if we assign null, well, it's null out.put(left, NULL); } else if(left instanceof Local && right instanceof Local) { out.put(left, out.get(right)); } else { out.put(left, TOP); } }
public void caseClassConstant(ClassConstant c) { // "array class" types are unmodified boolean classIsArray = c.value.startsWith("["); String className = classIsArray ? c.value : SootToDexUtils.getDexClassName(c.value); BuilderReference referencedClass = dexFile.internTypeReference(className); stmtV.addInsn(new Insn21c(Opcode.CONST_CLASS, destinationReg, referencedClass), origStmt); }
@Override public void constant( Constant c ) { if (c instanceof ClassConstant) { handleIndent(); String fullClassName = ((ClassConstant)c).value.replaceAll("/", "."); output.append(fullClassName + ".class"); } else { super.constant(c); } }
public Expression lookupClassConstant(ClassConstant cc) { if (!cConstantTypeMap.containsKey(cc.getValue())) { String name = TranslationHelpers.replaceIllegalChars("CC$" + cc.value); IdentifierExpression ide = this.pf.mkIdentifierExpression(this.getBoogieType(cc.getType()), name, true, true, true); cConstantTypeMap.put(cc.getValue(), ide); } return cConstantTypeMap.get(cc.getValue()); }
/** * Returns the set of possible values of a variable of type class. * * @param value The variable whose value we are looking for. * @param start The statement where the analysis should start. * @return The set of possible values for the variable. */ @Override public Set<Object> computeVariableValues(Value value, Stmt start) { if (value instanceof ClassConstant) { return Collections.singleton((Object) ((ClassConstant) value).getValue()); } else if (value instanceof Local) { return processClassAssignments( findAssignmentsForLocal(start, (Local) value, true, new HashSet<Pair<Unit, Local>>()), new HashSet<Stmt>()); } else { return Collections.singleton((Object) TOP_VALUE); } }
public Expression lookupClassConstant(ClassConstant cc) { if (!cConstantTypeMap.containsKey(cc.getValue())) { String name = TranslationHelpers.replaceIllegalChars("CC$"+cc.value); IdentifierExpression ide = this.pf.mkIdentifierExpression(this.getBoogieType(cc.getType()), name, true, true, true); cConstantTypeMap.put(cc.getValue(), ide); } return cConstantTypeMap.get(cc.getValue()); }
/** * It is not neccessary to treat a constant. * @param v a constant */ @Override public void caseClassConstant(ClassConstant v) { logger.finest("ClassConstant identified " + callingStmt.toString()); rightElement = RightElement.NOT; if (actualContext == StmtContext.ASSIGNRIGHT) { throw new InternalAnalyzerException(); } }
/** * Add a static field. This field is added to its corresponding class object. * @param field SootField */ public static void addStaticFieldToObjectMap(SootField field) { logger.info( "Adding static Field " + field.toString() + " to Object Map"); String signature = getSignatureForField(field); ArrayList<Type> parameterTypes = new ArrayList<Type>(); parameterTypes.add(RefType.v("java.lang.Object")); parameterTypes.add(RefType.v("java.lang.String")); SootClass sc = field.getDeclaringClass(); Unit assignDeclaringClass = Jimple.v().newAssignStmt( local_for_Objects, ClassConstant.v(sc.getName().replace(".", "/"))); Unit assignSignature = Jimple.v().newAssignStmt( local_for_Strings, StringConstant.v(signature)); Expr addObj = Jimple.v().newVirtualInvokeExpr( hs, Scene.v().makeMethodRef(Scene.v().getSootClass(HANDLE_CLASS), "addFieldToObjectMap", parameterTypes, Scene.v().getObjectType(), false), local_for_Objects, local_for_Strings); Unit assignExpr = Jimple.v().newInvokeStmt(addObj); unitStore_After.insertElement( unitStore_After.new Element(assignDeclaringClass, lastPos)); unitStore_After.insertElement( unitStore_After.new Element(assignSignature, assignDeclaringClass)); unitStore_After.insertElement( unitStore_After.new Element(assignExpr, assignSignature)); lastPos = assignExpr; }
/** * @param f * @param pos */ public static void addLevelInAssignStmt(StaticFieldRef f, Unit pos) { logger.info( "Adding Level of static Field " + f.toString() + " in assign stmt"); SootField field = f.getField(); String signature = getSignatureForField(field); ArrayList<Type> parameterTypes = new ArrayList<Type>(); parameterTypes.add(RefType.v("java.lang.Object")); parameterTypes.add(RefType.v("java.lang.String")); SootClass sc = field.getDeclaringClass(); Unit assignDeclaringClass = Jimple.v().newAssignStmt( local_for_Objects, ClassConstant.v(sc.getName().replace(".", "/"))); Unit assignSignature = Jimple.v().newAssignStmt( local_for_Strings, StringConstant.v(signature)); Expr addObj = Jimple.v().newVirtualInvokeExpr( hs, Scene.v().makeMethodRef(Scene.v().getSootClass(HANDLE_CLASS), "joinLevelOfFieldAndAssignmentLevel", parameterTypes, Scene.v().getObjectType(), false), local_for_Objects, local_for_Strings); Unit assignExpr = Jimple.v().newInvokeStmt(addObj); unitStore_Before.insertElement( unitStore_Before.new Element(assignDeclaringClass, pos)); unitStore_Before.insertElement(unitStore_Before.new Element(assignSignature, pos)); unitStore_Before.insertElement(unitStore_Before.new Element(assignExpr, pos)); lastPos = pos; }
/** * Creates a new node for a constant. */ private NewExpr constantNewExpr(Constant constant) { if (constant instanceof StringConstant) { return STRING_SITE; } else if (constant instanceof ClassConstant) { return CLASS_SITE; } else if (constant instanceof NullConstant) { return null; } else { throw new RuntimeException(constant.toString()); } }
public void caseClassConstant(ClassConstant v) { printConstant(v, "\""+v.value+"\""); }
public void outAClzzConstant(AClzzConstant node) { String s = (String)mProductions.removeLast(); mProductions.addLast(ClassConstant.v(s)); }
public Set<ClassConstant> possibleClassConstants() { return delegate.possibleClassConstants(); }
public Set<ClassConstant> possibleClassConstants() { return wrapped.possibleClassConstants(); }
public ClassConstant getClassConstant() { return (ClassConstant) newExpr; }
ClassConstantNode( PAG pag, ClassConstant cc ) { super( pag, cc, RefType.v( "java.lang.Class" ), null ); }
public void caseIfStmt(IfStmt stmt) { if (uses) { ConditionExpr cond = (ConditionExpr) stmt.getCondition(); BinopExpr expr = cond; Value lv = expr.getOp1(); Value rv = expr.getOp2(); TypeVariable lop; TypeVariable rop; // ******** LEFT ******** if (lv instanceof Local) { lop = resolver.typeVariable((Local) lv); } else if (lv instanceof DoubleConstant) { lop = resolver.typeVariable(DoubleType.v()); } else if (lv instanceof FloatConstant) { lop = resolver.typeVariable(FloatType.v()); } else if (lv instanceof IntConstant) { lop = resolver.typeVariable(IntType.v()); } else if (lv instanceof LongConstant) { lop = resolver.typeVariable(LongType.v()); } else if (lv instanceof NullConstant) { lop = resolver.typeVariable(NullType.v()); } else if (lv instanceof StringConstant) { lop = resolver.typeVariable(RefType.v("java.lang.String")); } else if (lv instanceof ClassConstant) { lop = resolver.typeVariable(RefType.v("java.lang.Class")); } else { throw new RuntimeException("Unhandled binary expression left operand type: " + lv.getClass()); } // ******** RIGHT ******** if (rv instanceof Local) { rop = resolver.typeVariable((Local) rv); } else if (rv instanceof DoubleConstant) { rop = resolver.typeVariable(DoubleType.v()); } else if (rv instanceof FloatConstant) { rop = resolver.typeVariable(FloatType.v()); } else if (rv instanceof IntConstant) { rop = resolver.typeVariable(IntType.v()); } else if (rv instanceof LongConstant) { rop = resolver.typeVariable(LongType.v()); } else if (rv instanceof NullConstant) { rop = resolver.typeVariable(NullType.v()); } else if (rv instanceof StringConstant) { rop = resolver.typeVariable(RefType.v("java.lang.String")); } else if (rv instanceof ClassConstant) { rop = resolver.typeVariable(RefType.v("java.lang.Class")); } else { throw new RuntimeException("Unhandled binary expression right operand type: " + rv.getClass()); } TypeVariable common = resolver.typeVariable(); rop.addParent(common); lop.addParent(common); } }
private Register asConstant(Value v, ConstantVisitor constantV) { Constant c = (Constant) v; Register constantRegister = null; List<Register> rArray = null; AtomicInteger iI = null; if (c instanceof ClassConstant) { rArray = classConstantReg; iI = classI; } else if (c instanceof NullConstant) { rArray = nullConstantReg; iI = nullI; } else if (c instanceof FloatConstant) { rArray = floatConstantReg; iI = floatI; } else if (c instanceof IntConstant) { rArray = intConstantReg; iI = intI; } else if (c instanceof LongConstant) { rArray = longConstantReg; iI = longI; } else if (c instanceof DoubleConstant) { rArray = doubleConstantReg; iI = doubleI; } else if (c instanceof StringConstant) { rArray = stringConstantReg; iI = stringI; } else { throw new RuntimeException("Error. Unknown constant type: '"+ c.getType() +"'"); } if (rArray.size() == 0 || iI.intValue() >= rArray.size()) { rArray.add(new Register(c.getType(), nextRegNum)); nextRegNum += SootToDexUtils.getDexWords(c.getType()); } constantRegister = rArray.get(iI.intValue()).clone(); iI.set(iI.intValue() + 1); // "load" constant into the register... constantV.setDestination(constantRegister); c.apply(constantV); // ...but return an independent register object return constantRegister.clone(); }
public Value createJimpleConstantValue(cp_info[] constant_pool) { CONSTANT_Utf8_info ci = (CONSTANT_Utf8_info)(constant_pool[name_index]); String name = ci.convert(); return ClassConstant.v(name); }
public void caseClassConstant(ClassConstant c) { }
@Override public void caseClassConstant(ClassConstant arg0) { this.expressionStack.push(GlobalsCache.v().lookupClassConstant(arg0)); }
/** * Returns the variable values that are associated with an call statement. * * @param sourceStmt The statement at which we should start. * @param visitedStmts The set of visited statements. * @return The set of possible values. */ protected Set<Object> handleInvokeExpression(Stmt sourceStmt, Set<Stmt> visitedStmts) { if (visitedStmts.contains(sourceStmt)) { return Collections.emptySet(); } else { visitedStmts.add(sourceStmt); } Iterator<Edge> edges = Scene.v().getCallGraph().edgesOutOf(sourceStmt); Set<Object> result = new HashSet<>(); while (edges.hasNext()) { Edge edge = edges.next(); SootMethod target = edge.getTgt().method(); if (target.isConcrete()) { for (Unit unit : target.getActiveBody().getUnits()) { if (unit instanceof ReturnStmt) { ReturnStmt returnStmt = (ReturnStmt) unit; Value returnValue = returnStmt.getOp(); if (returnValue instanceof StringConstant) { result.add(((StringConstant) returnValue).value); } else if (returnValue instanceof ClassConstant) { result.add(((ClassConstant) returnValue).value); } else if (returnValue instanceof Local) { List<DefinitionStmt> assignStmts = findAssignmentsForLocal(returnStmt, (Local) returnValue, true, new HashSet<Pair<Unit, Local>>()); Set<Object> classConstants = processClassAssignments(assignStmts, visitedStmts); if (classConstants == null || classConstants.contains(TOP_VALUE) || classConstants.contains(Constants.ANY_STRING)) { return null; } else { result.addAll(classConstants); } } else { return null; } } } } } return result; }
@Override public void visit(Value e) { if (e instanceof ClassConstant) { add((ClassConstant) e); } }
@Override public void caseClassConstant(ClassConstant v) { throwInvalidWriteException(v); }
@Override public void caseClassConstant(ClassConstant v) { addReadComponent(getWeakestSecurityLevel()); }
/** * @param f * @param pos */ public static void setLevelOfAssignStmt(StaticFieldRef f, Unit pos) { logger.info( "Set Level of static Field " + f.toString() + " in assign stmt"); SootField field = f.getField(); String signature = getSignatureForField(field); System.out.println("Signature of static field in jimple injector " + signature); ArrayList<Type> parameterTypes = new ArrayList<Type>(); parameterTypes.add(RefType.v("java.lang.Object")); parameterTypes.add(RefType.v("java.lang.String")); SootClass sc = field.getDeclaringClass(); Unit assignDeclaringClass = Jimple.v().newAssignStmt( local_for_Objects, ClassConstant.v(sc.getName().replace(".", "/"))); Unit assignSignature = Jimple.v().newAssignStmt( local_for_Strings, StringConstant.v(signature)); // insert: checkGlobalPC(Object, String) Expr checkGlobalPC = Jimple.v().newVirtualInvokeExpr( hs, Scene.v().makeMethodRef( Scene.v().getSootClass(HANDLE_CLASS), "checkGlobalPC", parameterTypes, VoidType.v(), false), local_for_Objects, local_for_Strings); Unit checkGlobalPCExpr = Jimple.v().newInvokeStmt(checkGlobalPC); // Add setLevelOfField Expr addObj = Jimple.v().newVirtualInvokeExpr( hs, Scene.v().makeMethodRef(Scene.v().getSootClass(HANDLE_CLASS), "setLevelOfField", parameterTypes, Scene.v().getObjectType(), false), local_for_Objects, local_for_Strings); Unit assignExpr = Jimple.v().newInvokeStmt(addObj); unitStore_Before.insertElement( unitStore_Before.new Element(assignDeclaringClass, pos)); unitStore_Before.insertElement(unitStore_Before.new Element(assignSignature, pos)); unitStore_Before.insertElement(unitStore_Before.new Element(checkGlobalPCExpr, pos)); unitStore_Before.insertElement(unitStore_Before.new Element(assignExpr, pos)); lastPos = pos; }
/** * The method should update the <em>security level</em> of a * {@link ClassConstant}, but it is not possible to update the level of a * constant. * * @param v * The constant for which the <em>security level</em> should be * updated. * @see soot.jimple.ConstantSwitch#caseClassConstant(soot.jimple.ClassConstant) * @throws InvalidSwitchException * Always, because the update is not possible. */ @Override public void caseClassConstant(ClassConstant v) { throw new SwitchException(getMsg("exception.analysis.switch.update_error", this.getClass().getSimpleName(), v.getClass().getSimpleName(), v.toString(), getSourceLine())); }
/** * @return * @see soot.PointsToSet#possibleClassConstants() */ public Set<ClassConstant> possibleClassConstants() { return pts.possibleClassConstants(); }
/** If this points-to set consists entirely of objects of * type java.lang.Class of a known class, * returns a set of ClassConstant's that are these classes. * If this point-to set may contain something else, returns null. */ public Set<ClassConstant> possibleClassConstants();
/** * DOC * * @see soot.jimple.ConstantSwitch#caseClassConstant(soot.jimple.ClassConstant) */ @Override public void caseClassConstant(ClassConstant v) { }