/** * Gets the Soot Method form the given Soot Class */ private soot.SootMethodRef getMethodFromClass(soot.SootClass sootClass, String name, ArrayList paramTypes, soot.Type returnType, boolean isStatic) { soot.SootMethodRef ref = soot.Scene.v().makeMethodRef(sootClass, name, paramTypes, returnType, isStatic); return ref; }
/** Create an unresolved reference to a constructor. */ public SootMethodRef makeConstructorRef(SootClass declaringClass, List<Type> parameterTypes) { return makeMethodRef(declaringClass, SootMethod.constructorName, parameterTypes, VoidType.v(), false); }
public void outAUnnamedMethodSignature(AUnnamedMethodSignature node) { String className, methodName; List parameterList = new ArrayList(); if (node.getParameterList() != null) { parameterList = (List) mProductions.removeLast(); } Type type = (Type) mProductions.removeLast(); String name = (String) mProductions.removeLast(); SootClass sootClass = mResolver.makeClassRef(SootClass.INVOKEDYNAMIC_DUMMY_CLASS_NAME); SootMethodRef sootMethod = Scene.v().makeMethodRef(sootClass, name, parameterList, type, false); mProductions.addLast(sootMethod); }
public void outAMethodSignature(AMethodSignature node) { String className, methodName; List parameterList = new ArrayList(); if (node.getParameterList() != null) { parameterList = (List) mProductions.removeLast(); } methodName = (String) mProductions.removeLast(); Type type = (Type) mProductions.removeLast(); className = (String) mProductions.removeLast(); SootClass sootClass = mResolver.makeClassRef(className); SootMethodRef sootMethod = Scene.v().makeMethodRef(sootClass, methodName, parameterList, type, false); mProductions.addLast(sootMethod); }
public SootMethodRef makeRef() { return Scene.v().makeMethodRef(declaringClass, name, parameterTypes == null ? null : Arrays.asList(parameterTypes), returnType, isStatic()); }
/** * @ast method * @aspect AutoBoxingCodegen * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddExtensions/Jimple1.5Backend/AutoBoxingCodegen.jrag:57 */ protected soot.Value emitBoxingOperation(Body b, soot.Value v, ASTNode location) { // Box the value on the stack into this Reference type ArrayList parameters = new ArrayList(); parameters.add(unboxed().getSootType()); SootMethodRef ref = Scene.v().makeMethodRef(getSootClassDecl(), "valueOf", parameters, getSootType(), true); ArrayList args = new ArrayList(); args.add(asLocal(b, v)); return b.newStaticInvokeExpr(ref, args, location); }
/** Return a SootMethodRef for the given data. * * @param sc The SootClass that the method is declared in * @param name The name of the method being invoked * @param returnType The return type of the method being invoked * @param paramTypes The parameter types of the method being invoked * @param kind The type of the invocation in terms of MethodHandle.Kind * @return A SootMethodRef */ protected SootMethodRef getSootMethodRef(SootClass sc, String name, String returnType, List<? extends CharSequence> paramTypes, Kind kind) { return Scene.v().makeMethodRef(sc, name, convertParameterTypes(paramTypes), DexType.toSoot(returnType), kind == Kind.REF_INVOKE_STATIC); }
public void outAStaticInvokeExpr(AStaticInvokeExpr node) { List args; if (node.getArgList() != null) { args = (List) mProductions.removeLast(); } else { args = new ArrayList(); } SootMethodRef method = (SootMethodRef) mProductions.removeLast(); method = Scene.v().makeMethodRef(method.declaringClass(), method.name(), method.parameterTypes(), method.returnType(), true); mProductions.addLast(Jimple.v().newStaticInvokeExpr(method, args)); }
public Value createJimpleConstantValue(cp_info[] constant_pool) { CONSTANT_Class_info cc = (CONSTANT_Class_info) (constant_pool[class_index]); CONSTANT_NameAndType_info cn = (CONSTANT_NameAndType_info) (constant_pool[name_and_type_index]); String className = cc.toString(constant_pool); String nameAndType = cn.toString(constant_pool); String name = nameAndType.substring(0, nameAndType.indexOf(":")); String typeName = nameAndType.substring(nameAndType.indexOf(":") + 1); List parameterTypes; Type returnType; // Generate parameters & returnType & parameterTypes { Type[] types = Util.v().jimpleTypesOfFieldOrMethodDescriptor(typeName); parameterTypes = new ArrayList(); for (int k = 0; k < types.length - 1; k++) { parameterTypes.add(types[k]); } returnType = types[types.length - 1]; } return Jimple.v().newStaticInvokeExpr( Scene.v().makeMethodRef(Scene.v().getSootClass(className), name, parameterTypes, returnType, true)); }
public static SootMethodRef makeMethodRef(String cName, String mName, String rType, List<String> pTypes, boolean isStatic) { SootClass sc = SootResolver.v().makeClassRef(cName); Type returnType = null; if (rType == "") { returnType = VoidType.v(); } else { returnType = RefType.v(rType); } List<Type> parameterTypes = new ArrayList<Type>(); for (String p : pTypes) { parameterTypes.add(RefType.v(p)); } return Scene.v().makeMethodRef(sc, mName, parameterTypes, returnType, isStatic); } }
/** * @ast method * @aspect AutoBoxingCodegen * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddExtensions/Jimple1.5Backend/AutoBoxingCodegen.jrag:83 */ protected soot.Value emitUnboxingOperation(Body b, soot.Value v, ASTNode location) { // Unbox the value on the stack from this Reference type SootMethodRef ref = Scene.v().makeMethodRef(getSootClassDecl(), unboxed().name() + "Value", new ArrayList(), unboxed().getSootType(), false); return b.newVirtualInvokeExpr(asLocal(b, v), ref, new ArrayList(), location); }
private SootMethodRef toSootMethodRef(Handle methodHandle) { String bsmClsName = AsmUtil.toQualifiedName(methodHandle.getOwner()); SootClass bsmCls = Scene.v().getSootClass(bsmClsName); List<Type> bsmSigTypes = AsmUtil.toJimpleDesc(methodHandle.getDesc()); Type returnType = bsmSigTypes.remove(bsmSigTypes.size() - 1); return Scene.v().makeMethodRef(bsmCls, methodHandle.getName(), bsmSigTypes, returnType, methodHandle.getTag() == MethodHandle.Kind.REF_INVOKE_STATIC.getValue()); }
/** * @apilevel internal */ private SootMethodRef sootRef_compute() { ArrayList parameters = new ArrayList(); for (int i = 0; i < getNumParameter(); i++) parameters.add(getParameter(i).type().getSootType()); SootMethodRef ref = Scene.v().makeMethodRef(hostType().getSootClassDecl(), name(), parameters, type().getSootType(), isStatic()); return ref; }
/** * @ast method * @aspect GenericsCodegen * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddExtensions/Jimple1.5Backend/GenericsCodegen.jrag:182 */ private SootMethodRef sootRef() { MethodDecl decl = decl().erasedMethod(); ArrayList parameters = new ArrayList(); for(int i = 0; i < decl.getNumParameter(); i++) parameters.add(decl.getParameter(i).type().getSootType()); SootMethodRef ref = Scene.v().makeMethodRef( methodQualifierType().getSootClassDecl(), decl.name(), parameters, decl.type().getSootType(), decl.isStatic() ); return ref; } /**
/** * Insert a runtime exception before unit u of body b. Useful to analyze broken code (which make reference to inexisting * class for instance) exceptionType: e.g., "java.lang.RuntimeException" */ public static void addExceptionAfterUnit(Body b, String exceptionType, Unit u, String m) { LocalCreation lc = new LocalCreation(b.getLocals()); Local l = lc.newLocal(RefType.v(exceptionType)); List<Unit> newUnits = new ArrayList<Unit>(); Unit u1 = Jimple.v().newAssignStmt(l, Jimple.v().newNewExpr(RefType.v(exceptionType))); Unit u2 = Jimple.v() .newInvokeStmt(Jimple.v().newSpecialInvokeExpr(l, Scene.v().makeMethodRef(Scene.v().getSootClass(exceptionType), "<init>", Collections.singletonList((Type) RefType.v("java.lang.String")), VoidType.v(), false), StringConstant.v(m))); Unit u3 = Jimple.v().newThrowStmt(l); newUnits.add(u1); newUnits.add(u2); newUnits.add(u3); b.getUnits().insertBefore(newUnits, u); }
private soot.Local createToString(soot.Local sb, polyglot.ast.Expr expr) { // invoke toString on local (type StringBuffer) soot.Local newString = lg.generateLocal(soot.RefType.v("java.lang.String")); soot.SootClass classToInvoke2 = soot.Scene.v().getSootClass("java.lang.StringBuffer"); soot.SootMethodRef methodToInvoke2 = soot.Scene.v().makeMethodRef(classToInvoke2, "toString", new ArrayList(), soot.RefType.v("java.lang.String"), false); soot.jimple.VirtualInvokeExpr toStringInvoke = soot.jimple.Jimple.v().newVirtualInvokeExpr(sb, methodToInvoke2); soot.jimple.Stmt lastAssign = soot.jimple.Jimple.v().newAssignStmt(newString, toStringInvoke); body.getUnits().add(lastAssign); Util.addLnPosTags(lastAssign, expr.position()); return newString; }
private void insertCastOrBoxingCode(Local lhs, Local rhs, Chain<Unit> newUnits) { // if assigning to a primitive type then there's nothing to do if (lhs.getType() instanceof RefLikeType) { if ((rhs.getType() instanceof RefLikeType)) { // insert cast newUnits.add(Jimple.v().newAssignStmt(lhs, Jimple.v().newCastExpr(rhs, lhs.getType()))); } else { // primitive type in rhs; insert boxing code RefType boxedType = ((PrimType) rhs.getType()).boxedType(); SootMethodRef ref = Scene.v().makeMethodRef(boxedType.getSootClass(), "valueOf", Collections.<Type>singletonList(rhs.getType()), boxedType, true); newUnits.add(Jimple.v().newAssignStmt(lhs, Jimple.v().newStaticInvokeExpr(ref, rhs))); } } }
private void insertCastOrUnboxingCode(Local lhs, Local rhs, Chain<Unit> newUnits) { // if assigning to a reference type then there's nothing to do if (lhs.getType() instanceof PrimType) { if ((rhs.getType() instanceof PrimType)) { // insert cast newUnits.add(Jimple.v().newAssignStmt(lhs, Jimple.v().newCastExpr(rhs, lhs.getType()))); } else { // reference type in rhs; insert unboxing code RefType boxedType = (RefType) rhs.getType(); SootMethodRef ref = Scene.v().makeMethodRef(boxedType.getSootClass(), lhs.getType().toString() + "Value", Collections.<Type>emptyList(), lhs.getType(), false); newUnits.add(Jimple.v().newAssignStmt(lhs, Jimple.v().newVirtualInvokeExpr(rhs, ref))); } } }
private soot.Local createStringBuffer(polyglot.ast.Expr expr) { // create and add one string buffer soot.Local local = lg.generateLocal(soot.RefType.v("java.lang.StringBuffer")); soot.jimple.NewExpr newExpr = soot.jimple.Jimple.v().newNewExpr(soot.RefType.v("java.lang.StringBuffer")); soot.jimple.Stmt assign = soot.jimple.Jimple.v().newAssignStmt(local, newExpr); body.getUnits().add(assign); Util.addLnPosTags(assign, expr.position()); soot.SootClass classToInvoke1 = soot.Scene.v().getSootClass("java.lang.StringBuffer"); soot.SootMethodRef methodToInvoke1 = soot.Scene.v().makeMethodRef(classToInvoke1, "<init>", new ArrayList(), soot.VoidType.v(), false); soot.jimple.SpecialInvokeExpr invoke = soot.jimple.Jimple.v().newSpecialInvokeExpr(local, methodToInvoke1); soot.jimple.Stmt invokeStmt = soot.jimple.Jimple.v().newInvokeStmt(invoke); body.getUnits().add(invokeStmt); Util.addLnPosTags(invokeStmt, expr.position()); return local; }
@Override protected soot.SootMethodRef getSootMethodRef(polyglot.ast.Call call) { soot.Type sootRecType; soot.SootClass receiverTypeClass; if (Util.getSootType(call.methodInstance().container()).equals(soot.RefType.v("java.lang.Object"))) { sootRecType = soot.RefType.v("java.lang.Object"); receiverTypeClass = soot.Scene.v().getSootClass("java.lang.Object"); } else { if (call.target().type() == null) { sootRecType = Util.getSootType(call.methodInstance().container()); } else { sootRecType = Util.getSootType(call.target().type()); } if (sootRecType instanceof soot.RefType) { receiverTypeClass = ((soot.RefType) sootRecType).getSootClass(); } else if (sootRecType instanceof soot.ArrayType) { receiverTypeClass = soot.Scene.v().getSootClass("java.lang.Object"); } else { throw new RuntimeException("call target problem: " + call); } } polyglot.types.MethodInstance methodInstance = call.methodInstance(); soot.Type sootRetType = Util.getSootType(methodInstance.returnType()); ArrayList sootParamsTypes = getSootParamsTypes(call); soot.SootMethodRef callMethod = soot.Scene.v().makeMethodRef(receiverTypeClass, methodInstance.name(), sootParamsTypes, sootRetType, methodInstance.flags().isStatic()); return callMethod; }