public static Pair<Value, List<Unit>> generateParameterArray(List<Value> parameterList, Body body){ List<Unit> generated = new ArrayList<Unit>(); NewArrayExpr arrayExpr = Jimple.v().newNewArrayExpr(RefType.v("java.lang.Object"), IntConstant.v(parameterList.size())); Value newArrayLocal = generateFreshLocal(body, getParameterArrayType()); Unit newAssignStmt = Jimple.v().newAssignStmt(newArrayLocal, arrayExpr); generated.add(newAssignStmt); for(int i = 0; i < parameterList.size(); i++){ Value index = IntConstant.v(i); ArrayRef leftSide = Jimple.v().newArrayRef(newArrayLocal, index); Value rightSide = generateCorrectObject(body, parameterList.get(i), generated); Unit parameterInArray = Jimple.v().newAssignStmt(leftSide, rightSide); generated.add(parameterInArray); } return new Pair<Value, List<Unit>>(newArrayLocal, generated); }
/** * Constructs an array of the given type with a single element of this type * in the given method * @param body The body of the method in which to create the array * @param gen The local generator * @param tp The type of which to create the array * @param constructionStack Set of classes currently being built to avoid * constructor loops * @param parentClasses If a requested type is compatible with one of the * types in this list, the already-created object is used instead of * creating a new one. * @return The local referencing the newly created array, or null if the * array generation failed */ private Value buildArrayOfType(Body body, LocalGenerator gen, ArrayType tp, Set<SootClass> constructionStack, Set<SootClass> parentClasses) { Local local = gen.generateLocal(tp); // Generate a new single-element array NewArrayExpr newArrayExpr = Jimple.v().newNewArrayExpr(tp.getElementType(), IntConstant.v(1)); AssignStmt assignArray = Jimple.v().newAssignStmt(local, newArrayExpr); body.getUnits().add(assignArray); // Generate a single element in the array AssignStmt assign = Jimple.v().newAssignStmt (Jimple.v().newArrayRef(local, IntConstant.v(0)), getValueForType(body, gen, tp.getElementType(), constructionStack, parentClasses)); body.getUnits().add(assign); return local; }
public void caseNewArrayExpr(NewArrayExpr v) { String oldName = varName; Value size = v.getSize(); suggestVariableName("size"); String sizeName = varName; size.apply(this); suggestVariableName("type"); String lhsName = varName; ttp.setVariableName(varName); v.getType().apply(ttp); p.println("Value "+oldName+" = Jimple.v().newNewArrayExpr("+lhsName+", "+sizeName+");"); varName = oldName; }
private boolean isObjectArray(Value v, Body body) { for (Unit u : body.getUnits()) { if (u instanceof AssignStmt) { AssignStmt assign = (AssignStmt) u; if (assign.getLeftOp() == v) { if (assign.getRightOp() instanceof NewArrayExpr) { NewArrayExpr nea = (NewArrayExpr) assign.getRightOp(); if (isObject(nea.getBaseType())) return true; } else if (assign.getRightOp() instanceof FieldRef) { FieldRef fr = (FieldRef) assign.getRightOp(); if (fr.getType() instanceof ArrayType) if (isObject(((ArrayType) fr.getType()) .getArrayElementType())) return true; } } } } return false; }
private void javafy_expr(ValueBox vb) { Expr e = (Expr) vb.getValue(); if (e instanceof BinopExpr) javafy_binop_expr(vb); else if (e instanceof UnopExpr) javafy_unop_expr(vb); else if (e instanceof CastExpr) javafy_cast_expr(vb); else if (e instanceof NewArrayExpr) javafy_newarray_expr(vb); else if (e instanceof NewMultiArrayExpr) javafy_newmultiarray_expr(vb); else if (e instanceof InstanceOfExpr) javafy_instanceof_expr(vb); else if (e instanceof InvokeExpr) javafy_invoke_expr(vb); else if (e instanceof NewExpr) javafy_new_expr(vb); }
Type h2t(Unit h) { if(h instanceof JAssignStmt){ JAssignStmt j = (JAssignStmt)h; if(SootUtilities.isNewStmt(j)){ NewExpr ne = (NewExpr)j.rightBox.getValue(); return ne.getType(); }else if(SootUtilities.isNewArrayStmt(j)){ NewArrayExpr nae = (NewArrayExpr)j.rightBox.getValue(); return nae.getType(); }else if(SootUtilities.isNewMultiArrayStmt(j)){ JNewMultiArrayExpr jnmae = (JNewMultiArrayExpr)j.rightBox.getValue(); return jnmae.getType(); } } return null; }
/** * Constructs an array of the given type with a single element of this type * in the given method * @param body The body of the method in which to create the array * @param gen The local generator * @param tp The type of which to create the array * @param constructionStack Set of classes currently being built to avoid * constructor loops * @param parentClasses If a requested type is compatible with one of the * types in this list, the already-created object is used instead of * creating a new one. * @return The local referencing the newly created array, or null if the * array generation failed */ private Value buildArrayOfType(JimpleBody body, LocalGenerator gen, ArrayType tp, Set<SootClass> constructionStack, Set<SootClass> parentClasses) { Local local = gen.generateLocal(tp); // Generate a new single-element array NewArrayExpr newArrayExpr = Jimple.v().newNewArrayExpr(tp.getElementType(), IntConstant.v(1)); AssignStmt assignArray = Jimple.v().newAssignStmt(local, newArrayExpr); body.getUnits().add(assignArray); // Generate a single element in the array AssignStmt assign = Jimple.v().newAssignStmt (Jimple.v().newArrayRef(local, IntConstant.v(19)), getValueForType(body, gen, tp.getElementType(), constructionStack, parentClasses)); body.getUnits().add(assign); return local; }
/** * * @param parameter * @param body * @return */ private Pair<Value, List<Unit>> generateParameterArray(List<Value> parameter, Body body){ List<Unit> generated = new ArrayList<Unit>(); NewArrayExpr arrayExpr = Jimple.v().newNewArrayExpr(RefType.v("java.lang.Object"), IntConstant.v(parameter.size())); Value newArrayLocal = generateFreshLocal(body, getParameterArrayType()); Unit newAssignStmt = Jimple.v().newAssignStmt(newArrayLocal, arrayExpr); generated.add(newAssignStmt); for(int i = 0; i < parameter.size(); i++){ Value index = IntConstant.v(i); ArrayRef leftSide = Jimple.v().newArrayRef(newArrayLocal, index); Value rightSide = generateCorrectObject(body, parameter.get(i), generated); Unit parameterInArray = Jimple.v().newAssignStmt(leftSide, rightSide); generated.add(parameterInArray); } return new Pair<Value, List<Unit>>(newArrayLocal, generated); }
/** * Returns a points-to graph with the locals of main initialised to * <tt>null</tt>, except the command-line arguments which are * initialised to an array of strings. */ @Override public PointsToGraph boundaryValue(SootMethod entryPoint) { // For now we only support entry to the main method assert(entryPoint == Scene.v().getMainMethod()); // Ok, start setting up entry value PointsToGraph entryValue = new PointsToGraph(); // Locals of main... (only reference types) SootMethod mainMethod = Scene.v().getMainMethod(); for (Local local : mainMethod.getActiveBody().getLocals()) { if (local.getType() instanceof RefLikeType) { entryValue.assign(local, null); } } // Command-line arguments to main... Local argsLocal = mainMethod.getActiveBody().getParameterLocal(0); NewArrayExpr argsExpr = new JNewArrayExpr(Scene.v().getRefType("java.lang.String"), IntConstant.v(0)); entryValue.assignNew(argsLocal, argsExpr); entryValue.setFieldConstant(argsLocal, PointsToGraph.ARRAY_FIELD, PointsToGraph.STRING_CONST); return entryValue; }
private boolean isArrayAlloc(Unit sourceStmt) { if (sourceStmt instanceof AssignStmt) { AssignStmt as = (AssignStmt) sourceStmt; if (as.getRightOp() instanceof NewArrayExpr) return true; } return false; }
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); } }
@Override public void caseNewArrayExpr(NewArrayExpr nae) { Value size = nae.getSize(); constantV.setOrigStmt(origStmt); Register sizeReg = regAlloc.asImmediate(size, constantV); ArrayType arrayType = nae.getBaseType().getArrayType(); BuilderReference arrayTypeItem = DexPrinter.toTypeReference (arrayType, stmtV.getBelongingFile()); stmtV.addInsn(new Insn22c(Opcode.NEW_ARRAY, destinationReg, sizeReg, arrayTypeItem), origStmt); }
public void jimplify (DexBody body) { if(!(instruction instanceof Instruction22c)) throw new IllegalArgumentException("Expected Instruction22c but got: "+instruction.getClass()); Instruction22c newArray = (Instruction22c)instruction; int dest = newArray.getRegisterA(); Value size = body.getRegisterLocal(newArray.getRegisterB()); Type t = DexType.toSoot((TypeReference) newArray.getReference()); // NewArrayExpr needs the ElementType as it increases the array dimension by 1 Type arrayType = ((ArrayType) t).getElementType(); Debug.printDbg("new array element type: ", arrayType); NewArrayExpr newArrayExpr = Jimple.v().newNewArrayExpr(arrayType, size); Local l = body.getRegisterLocal(dest); assign = Jimple.v().newAssignStmt(l, newArrayExpr); 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().setType(newArrayExpr.getSizeBox(), IntType.v(), true); DalvikTyper.v().setType(assign.getLeftOpBox(), newArrayExpr.getType(), false); } }
public void caseNewArrayExpr(NewArrayExpr expr) { if (expr.getBaseType() instanceof RefLikeType) { result = result.add(mgr.RESOLVE_CLASS_ERRORS); } Value count = expr.getSize(); if ((! (count instanceof IntConstant)) || (((IntConstant) count).lessThan(INT_CONSTANT_ZERO) .equals(INT_CONSTANT_ZERO))) { result = result.add(mgr.NEGATIVE_ARRAY_SIZE_EXCEPTION); } result = result.add(mightThrow(count)); }
@Override public void visit(Value e) { if (e instanceof NewArrayExpr) { NewArrayExpr nae = (NewArrayExpr) e; add(e, e.getType(), nae.getSize()); } }
@Override public void caseNewArrayExpr(NewArrayExpr v) { rightElement = RightElement.NEW_ARRAY; logger.finest("New Array expression identified: " + callingStmt.toString()); if (actualContext == StmtContext.ASSIGNRIGHT) { // TODO } }
@Override public void caseNewArrayExpr(NewArrayExpr v) { throw new RuntimeException("todo"); }
/** * Get the definition of the Array starting from an ArrayRef. * Two possibilities: * 1) array = IdentityStmt in which case the previous method in the stack is analyzed * 2) array = newarray in which case all statements array[i] = r are analyzed * @param stack * @param curDepth * @param ar * @param mpSet */ private static void getArrayFromMethod (Stack<SootMethod> stack, int curDepth, ArrayRef ar, Set<String> mpSet) { SootMethod targetM = stack.elementAt(curDepth); logger.info("getArrayFromMethod target: "+ targetM); Body b = targetM.getActiveBody(); System.out.println("body: "+ b); // TODO: change to logger.debug UnitGraph eug = new ExceptionalUnitGraph( b ); LocalDefinition ld = new LocalDefinition(b); Local l = (Local)ar.getBase(); List<Unit> arrayDefs = ld.collectDefinitionsWithAliases(l); for (Unit arrayDef: arrayDefs) { if (arrayDef instanceof IdentityStmt) { logger.info("array: right is IdentityStmt"); IdentityStmt ids = (IdentityStmt)arrayDef; ParameterRef pref = (ParameterRef)ids.getRightOp(); int paramPos = pref.getIndex(); logger.info("index of array parameter: "+ paramPos); // TODO: should be debug // List<MethodCall> methodCallsList = getStringParameterInCall(stack.elementAt(curDepth - 1), targetM, paramPos, mpSet); // getArrayFromMethod (stack, stack.size()-1, ar, mpSet); getStringFromMethod (stack, curDepth-1, targetM, paramPos, mpSet); } else if (arrayDef instanceof AssignStmt) { AssignStmt ass = (AssignStmt) arrayDef; Value right = ass.getRightOp(); if (right instanceof NewArrayExpr) { logger.info("array: right is NewArray"); // get the unit array[i] = str // TODO: Limitation: we suppose the array is initialized in the body where it is created // and that it is not aliased Local arrayLocal = (Local)ass.getLeftOp(); List<Value> arrayInitValues = retrieveArrayInitStmts (b, arrayLocal); for (Value v: arrayInitValues) { if (v instanceof StringConstant) { StringConstant sc = (StringConstant)v; String p = sc.value; mpSet.add(p); logger.info("add perm from array inif: "+ p); } else { logger.warn("not handling this value for array init: "+ v); } } } else if (right instanceof Local){ logger.info("alias "+ ass); // definitions *and* aliases are collected, so no need to handle them separately } else { throw new RuntimeException("error: right not instance of NewArrayExpr nor Local! "+ ass); } } } }
private boolean isAllocationSite(Value val) { return (val instanceof StringConstant || val instanceof NewExpr || val instanceof NewArrayExpr || val instanceof NewMultiArrayExpr); }
public void jimplify (DexBody body) { if(!(instruction instanceof Instruction3rc)) throw new IllegalArgumentException("Expected Instruction3rc but got: "+instruction.getClass()); Instruction3rc filledNewArrayInstr = (Instruction3rc)instruction; // NopStmt nopStmtBeginning = Jimple.v().newNopStmt(); // body.add(nopStmtBeginning); int usedRegister = filledNewArrayInstr.getRegisterCount(); Type t = DexType.toSoot((TypeReference) filledNewArrayInstr.getReference()); // NewArrayExpr needs the ElementType as it increases the array dimension by 1 Type arrayType = ((ArrayType) t).getElementType(); System.out.println("array element type (narr range): "+ arrayType); NewArrayExpr arrayExpr = Jimple.v().newNewArrayExpr(arrayType, IntConstant.v(usedRegister)); arrayLocal = body.getStoreResultLocal(); AssignStmt assignStmt = Jimple.v().newAssignStmt(arrayLocal, arrayExpr); body.add (assignStmt); for (int i = 0; i < usedRegister; i++) { ArrayRef arrayRef = Jimple.v().newArrayRef(arrayLocal, IntConstant.v(i)); AssignStmt assign = Jimple.v().newAssignStmt(arrayRef, body.getRegisterLocal(i + filledNewArrayInstr.getStartRegister())); addTags(assign); body.add(assign); } // NopStmt nopStmtEnd = Jimple.v().newNopStmt(); // body.add(nopStmtEnd); // defineBlock(nopStmtBeginning,nopStmtEnd); setUnit (assignStmt); // body.setDanglingInstruction(this); if (IDalvikTyper.ENABLE_DVKTYPER) { Debug.printDbg(IDalvikTyper.DEBUG, "constraint: "+ assignStmt); int op = (int)instruction.getOpcode().value; DalvikTyper.v().setType(assignStmt.getLeftOpBox(), arrayExpr.getType(), false); //DalvikTyper.v().addConstraint(assignStmt.getLeftOpBox(), assignStmt.getRightOpBox()); } }
private void javafy_newarray_expr(ValueBox vb) { NewArrayExpr nae = (NewArrayExpr) vb.getValue(); javafy(nae.getSizeBox()); vb.setValue(new DNewArrayExpr(nae.getBaseType(), nae.getSize())); }
private void convertIntInsn(IntInsnNode insn) { int op = insn.getOpcode(); StackFrame frame = getFrame(insn); Operand[] out = frame.out(); Operand opr; if (out == null) { Value v; if (op == BIPUSH || op == SIPUSH) { v = IntConstant.v(insn.operand); } else { Type type; switch (insn.operand) { case T_BOOLEAN: type = BooleanType.v(); break; case T_CHAR: type = CharType.v(); break; case T_FLOAT: type = FloatType.v(); break; case T_DOUBLE: type = DoubleType.v(); break; case T_BYTE: type = ByteType.v(); break; case T_SHORT: type = ShortType.v(); break; case T_INT: type = IntType.v(); break; case T_LONG: type = LongType.v(); break; default: throw new AssertionError("Unknown NEWARRAY type!"); } Operand size = popImmediate(); NewArrayExpr anew = Jimple.v().newNewArrayExpr(type, size.stackOrValue()); size.addBox(anew.getSizeBox()); frame.in(size); frame.boxes(anew.getSizeBox()); v = anew; } opr = new Operand(insn, v); frame.out(opr); } else { opr = out[0]; if (op == NEWARRAY) frame.mergeIn(pop()); } push(opr); }
@Override public void caseNewArrayExpr(NewArrayExpr arg0) { throw new RuntimeException("Must be handeled in SootStmtSwitch"); }
public static void translateAssignment(SootStmtSwitch ss, Value lhs, Value rhs, Unit statement) { ProgramFactory pf = GlobalsCache.v().getPf(); SootValueSwitch valueswitch = ss.getValueSwitch(); if (rhs instanceof InvokeExpr) { InvokeExpr ivk = (InvokeExpr) rhs; InvokeTranslation .translateInvokeAssignment(ss, lhs, ivk, statement); return; } valueswitch.isLeftHandSide = true; lhs.apply(valueswitch); valueswitch.isLeftHandSide = false; Expression left = valueswitch.getExpression(); Expression right; if (rhs instanceof NewExpr) { right = ss.createAllocatedVariable(((NewExpr) rhs).getBaseType()); } else if (rhs instanceof NewArrayExpr) { NewArrayExpr nae = (NewArrayExpr) rhs; right = ss.createAllocatedVariable(nae.getType()); nae.getSize().apply(valueswitch); Expression sizeexp = valueswitch.getExpression(); // add the size expression. ss.addStatement(GlobalsCache.v().setArraySizeStatement(right, sizeexp)); } else if (rhs instanceof NewMultiArrayExpr) { NewMultiArrayExpr nmae = (NewMultiArrayExpr) rhs; for (int i = 0; i < nmae.getSizeCount(); i++) { nmae.getSize(i).apply(valueswitch); // Expression sizeexp = valueswitch.getExpression(); // TODO Log.debug("Mulit-arrays are not implemented!"); } right = GlobalsCache.v().makeFreshGlobal( SootPrelude.v().getReferenceType(), true, true); } else if (rhs instanceof StringConstant) { StringConstant str = (StringConstant) rhs; // right = stringConstantMap.get(str); right = ss.createAllocatedVariable(rhs.getType()); Expression[] indices = { right }; // assign the size of the string to the appropriate field in the // $stringSizeHeapVariable array. translateAssignment( ss, SootPrelude.v().getStringSizeHeapVariable(), pf.mkArrayStoreExpression(SootPrelude.v() .getStringSizeHeapVariable().getType(), SootPrelude .v().getStringSizeHeapVariable(), indices, pf .mkIntLiteral(Integer.toString(str.value.length())))); } else { rhs.apply(valueswitch); right = valueswitch.getExpression(); } translateAssignment(ss, left, right); }
/** A new array statement */ protected void caseNewArrayStmt( Local dest, NewArrayExpr e ) {}
public final void caseAssignStmt( AssignStmt s ) { statement = s; Value lhs = s.getLeftOp(); Value rhs = s.getRightOp(); if( ! (lhs.getType() instanceof RefType) && ! (lhs.getType() instanceof ArrayType) ) { if( rhs instanceof InvokeExpr ) { caseInvokeStmt( null, (InvokeExpr) rhs ); return; } caseUninterestingStmt( s ); return; } if( rhs instanceof InvokeExpr ) { caseInvokeStmt( (Local) lhs, (InvokeExpr) rhs ); return; } if( lhs instanceof Local ) { if( rhs instanceof Local ) { caseCopyStmt( (Local) lhs, rhs ); } else if( rhs instanceof InstanceFieldRef ) { caseLoadStmt( (Local) lhs, (InstanceFieldRef) rhs ); } else if( rhs instanceof ArrayRef ) { caseArrayLoadStmt( (Local) lhs, (ArrayRef) rhs ); } else if( rhs instanceof StaticFieldRef ) { caseGlobalLoadStmt( (Local) lhs, (StaticFieldRef) rhs ); } else if( rhs instanceof NewExpr ) { caseNewStmt( (Local) lhs, (NewExpr) rhs ); } else if( rhs instanceof NewArrayExpr ) { caseNewArrayStmt( (Local) lhs, (NewArrayExpr) rhs ); } else if( rhs instanceof NewMultiArrayExpr ) { caseNewMultiArrayStmt( (Local) lhs, (NewMultiArrayExpr) rhs ); } else if( rhs instanceof CastExpr ) { CastExpr r = (CastExpr) rhs; Value rv = r.getOp(); caseCastStmt( (Local) lhs, rv, r ); } else if( rhs instanceof Constant ) { caseCopyStmt( (Local) lhs, rhs ); } else if( rhs instanceof PhiExpr ) { casePhiStmt( (Local) lhs, (PhiExpr) rhs ); } else throw new RuntimeException( "unhandled stmt "+s ); } else if( lhs instanceof InstanceFieldRef ) { if( rhs instanceof Local || rhs instanceof Constant) { caseStoreStmt( (InstanceFieldRef) lhs, rhs ); } else throw new RuntimeException( "unhandled stmt "+s ); } else if( lhs instanceof ArrayRef ) { if( rhs instanceof Local || rhs instanceof Constant ) { caseArrayStoreStmt( (ArrayRef) lhs, rhs ); } else throw new RuntimeException( "unhandled stmt "+s ); } else if( lhs instanceof StaticFieldRef ) { if( rhs instanceof Local || rhs instanceof Constant ) { caseGlobalStoreStmt( (StaticFieldRef) lhs, rhs ); } else throw new RuntimeException( "unhandled stmt "+s ); } else throw new RuntimeException( "unhandled stmt "+s ); }
public static void translateAssignment(SootStmtSwitch ss, Value lhs, Value rhs, Unit statement) { ProgramFactory pf = GlobalsCache.v().getPf(); SootValueSwitch valueswitch = ss.getValueSwitch(); if (rhs instanceof InvokeExpr) { InvokeExpr ivk = (InvokeExpr) rhs; InvokeTranslation .translateInvokeAssignment(ss, lhs, ivk, statement); return; } valueswitch.isLeftHandSide = true; lhs.apply(valueswitch); valueswitch.isLeftHandSide = false; Expression left = valueswitch.getExpression(); Expression right; if (rhs instanceof NewExpr) { right = ss.createAllocatedVariable(((NewExpr) rhs).getBaseType()); } else if (rhs instanceof NewArrayExpr) { NewArrayExpr nae = (NewArrayExpr) rhs; right = ss.createAllocatedVariable(nae.getType()); nae.getSize().apply(valueswitch); Expression sizeexp = valueswitch.getExpression(); // add the size expression. ss.addStatement(GlobalsCache.v().setArraySizeStatement(right, sizeexp)); } else if (rhs instanceof NewMultiArrayExpr) { NewMultiArrayExpr nmae = (NewMultiArrayExpr) rhs; for (int i = 0; i < nmae.getSizeCount(); i++) { nmae.getSize(i).apply(valueswitch); // Expression sizeexp = valueswitch.getExpression(); // TODO Log.error("Mulit-arrays are not implemented!"); } right = GlobalsCache.v().makeFreshGlobal( SootPrelude.v().getReferenceType(), true, true); } else if (rhs instanceof StringConstant) { StringConstant str = (StringConstant) rhs; // right = stringConstantMap.get(str); right = ss.createAllocatedVariable(rhs.getType()); Expression[] indices = { right }; // assign the size of the string to the appropriate field in the // $stringSizeHeapVariable array. translateAssignment( ss, SootPrelude.v().getStringSizeHeapVariable(), pf.mkArrayStoreExpression(SootPrelude.v() .getStringSizeHeapVariable().getType(), SootPrelude .v().getStringSizeHeapVariable(), indices, pf .mkIntLiteral(Integer.toString(str.value.length())))); } else { rhs.apply(valueswitch); right = valueswitch.getExpression(); } translateAssignment(ss, left, right); }
@Override public void caseNewArrayExpr(NewArrayExpr v) { throwInvalidWriteException(v); }
@Override public void caseNewArrayExpr(NewArrayExpr v) { throwIllegalNewArrayException(v); }
/** * Computes the targets of an invoke expression using a given points-to graph. * * <p>For static invocations, there is only target. For instance method * invocations, the targets depend on the type of receiver objects pointed-to * by the instance variable whose method is being invoked.</p> * * <p>If the instance variable points to a summary node, then the returned * value is <tt>null</tt> signifying a <em>default</em> call-site.</p> */ private Set<SootMethod> getTargets(SootMethod callerMethod, Stmt callStmt, InvokeExpr ie, PointsToGraph ptg) { Set<SootMethod> targets = new HashSet<SootMethod>(); SootMethod invokedMethod = ie.getMethod(); String subsignature = invokedMethod.getSubSignature(); // Static and special invocations refer to the target method directly if (ie instanceof StaticInvokeExpr || ie instanceof SpecialInvokeExpr) { targets.add(invokedMethod); return targets; } else { assert (ie instanceof InterfaceInvokeExpr || ie instanceof VirtualInvokeExpr); // Get the receiver Local receiver = (Local) ((InstanceInvokeExpr) ie).getBase(); // Get what objects the receiver points-to Set<AnyNewExpr> heapNodes = ptg.getTargets(receiver); if (heapNodes != null) { // For each object, find the invoked method for the declared type for (AnyNewExpr heapNode : heapNodes) { if (heapNode == PointsToGraph.SUMMARY_NODE) { // If even one pointee is a summary node, then this is a default site return null; } else if (heapNode instanceof NewArrayExpr) { // Probably getClass() or something like that on an array return null; } // Find the top-most class that declares a method with the given // signature and add it to the resulting targets SootClass sootClass = ((RefType) heapNode.getType()).getSootClass(); do { if (sootClass.declaresMethod(subsignature)) { targets.add(sootClass.getMethod(subsignature)); break; } else if (sootClass.hasSuperclass()) { sootClass = sootClass.getSuperclass(); } else { sootClass = null; } } while (sootClass != null); } } if (targets.isEmpty()) { // System.err.println("Warning! Null call at: " + callStmt+ " in " + callerMethod); } return targets; } }
/** * The method should update the <em>security level</em> of an expression * with type {@link NewArrayExpr}, but it is not possible to update the * level of such an expression. * * @param v * The expression for which the <em>security level</em> should be * updated. * @see soot.jimple.ExprSwitch#caseNewArrayExpr(soot.jimple.NewArrayExpr) * @throws InvalidSwitchException * Always, because the update is not possible. */ @Override public void caseNewArrayExpr(NewArrayExpr v) { throw new SwitchException(getMsg("exception.analysis.switch.update_error", this.getClass().getSimpleName(), v.getClass().getSimpleName(), v.toString(), getSourceLine())); }
/** * DOC * * @see soot.jimple.ExprSwitch#caseNewArrayExpr(soot.jimple.NewArrayExpr) */ @Override public void caseNewArrayExpr(NewArrayExpr v) { v.getSize().apply(this); }
/** * Looks up the <em>security level</em> for the given new expression and * stores the level in {@link SecurityLevelValueReadSwitch#level}. For a * {@link NewArrayExpr} this is the weakest available * <em>security level</em>. * * @param v * The new expression for which the <em>security level</em> * should be looked up. * @see soot.jimple.ExprSwitch#caseNewArrayExpr(soot.jimple.NewArrayExpr) */ @Override public void caseNewArrayExpr(NewArrayExpr v) { this.level = getWeakestSecurityLevel(); }