private soot.SootMethod createSootConstructor(String name, polyglot.types.Flags flags, ArrayList parameters, ArrayList<SootClass> exceptions) { int modifier = Util.getModifier(flags); soot.SootMethod method = Scene.v().makeSootMethod(name, parameters, soot.VoidType.v(), modifier, exceptions); return method; }
private soot.SootMethod createSootMethod(String name, polyglot.types.Flags flags, polyglot.types.Type returnType, ArrayList parameters, ArrayList<SootClass> exceptions) { int modifier = Util.getModifier(flags); soot.Type sootReturnType = Util.getSootType(returnType); soot.SootMethod method = Scene.v().makeSootMethod(name, parameters, sootReturnType, modifier, exceptions); return method; }
public void outAMethodMember(AMethodMember node) { int modifier = 0; Type type; String name; List parameterList = null; List<SootClass> throwsClause = null; if (node.getThrowsClause() != null) { throwsClause = (List<SootClass>) mProductions.removeLast(); } if (node.getParameterList() != null) { parameterList = (List) mProductions.removeLast(); } else { parameterList = new ArrayList(); } Object o = mProductions.removeLast(); name = (String) o; type = (Type) mProductions.removeLast(); modifier = processModifiers(node.getModifier()); SootMethod method; if (throwsClause != null) { method = Scene.v().makeSootMethod(name, parameterList, type, modifier, throwsClause); } else { method = Scene.v().makeSootMethod(name, parameterList, type, modifier); } mSootClass.addMethod(method); }
public MonitorConverter(Singletons.Global g) { SootClass davaMonitor = new SootClass("soot.dava.toolkits.base.DavaMonitor.DavaMonitor", Modifier.PUBLIC); davaMonitor.setSuperclass(Scene.v().loadClassAndSupport("java.lang.Object")); LinkedList objectSingleton = new LinkedList(); objectSingleton.add(RefType.v("java.lang.Object")); v = Scene.v().makeSootMethod("v", new LinkedList(), RefType.v("soot.dava.toolkits.base.DavaMonitor.DavaMonitor"), Modifier.PUBLIC | Modifier.STATIC); enter = Scene.v().makeSootMethod("enter", objectSingleton, VoidType.v(), Modifier.PUBLIC | Modifier.SYNCHRONIZED); exit = Scene.v().makeSootMethod("exit", objectSingleton, VoidType.v(), Modifier.PUBLIC | Modifier.SYNCHRONIZED); davaMonitor.addMethod(v); davaMonitor.addMethod(enter); davaMonitor.addMethod(exit); Scene.v().addClass(davaMonitor); }
method = Scene.v().makeSootMethod(name, parameterList, type, modifier, throwsClause); } else { method = Scene.v().makeSootMethod(name, parameterList, type, modifier);
private SootMethodRef makeMethodRef(String methodName, ArrayList args) { // make MethodRef for methodName SootMethod method = Scene.v().makeSootMethod(methodName, args, RefType.v("java.lang.Object")); // set the declaring class of new method to be the DavaSuperHandler // class method.setDeclaringClass(new SootClass("DavaSuperHandler")); return method.makeRef(); }
/** * @ast method * @aspect EmitJimple * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddExtensions/JimpleBackend/EmitJimple.jrag:145 */ public void jimplify1phase2() { if (needsClinit() && !getSootClassDecl().declaresMethod("<clinit>", new ArrayList())) { clinit = Scene.v().makeSootMethod("<clinit>", new ArrayList(), soot.VoidType.v(), soot.Modifier.STATIC, new ArrayList()); getSootClassDecl().addMethod(clinit); } for (Iterator iter = nestedTypes().iterator(); iter.hasNext();) { TypeDecl typeDecl = (TypeDecl) iter.next(); typeDecl.jimplify1phase2(); } for (int i = 0; i < getNumBodyDecl(); i++) if (getBodyDecl(i).generate()) getBodyDecl(i).jimplify1phase2(); addAttributes(); }
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { List<SootClass> thrownExceptions; if (exceptions == null || exceptions.length == 0) { thrownExceptions = Collections.emptyList(); } else { int len = exceptions.length; thrownExceptions = new ArrayList<SootClass>(len); for (int i = 0; i != len; i++) { String ex = AsmUtil.toQualifiedName(exceptions[i]); addDep(RefType.v(ex)); thrownExceptions.add(SootResolver.v().makeClassRef(ex)); } } List<soot.Type> sigTypes = AsmUtil.toJimpleDesc(desc); for (soot.Type type : sigTypes) { addDep(type); } SootMethod method = Scene.v().makeSootMethod(name, sigTypes, sigTypes.remove(sigTypes.size() - 1), access, thrownExceptions); if (signature != null) { method.addTag(new SignatureTag(signature)); } method = klass.getOrAddMethod(method); return new MethodBuilder(method, this, desc, exceptions); }
private soot.SootMethod makeLiFieldAccessMethod(soot.SootClass classToInvoke, polyglot.types.LocalInstance li) { String name = "access$" + soot.javaToJimple.InitialResolver.v().getNextPrivateAccessCounter() + "00"; ArrayList paramTypes = new ArrayList(); paramTypes.add(classToInvoke.getType()); soot.SootMethod meth = Scene.v().makeSootMethod(name, paramTypes, Util.getSootType(li.type()), soot.Modifier.STATIC); classToInvoke.addMethod(meth); PrivateFieldAccMethodSource src = new PrivateFieldAccMethodSource(Util.getSootType(li.type()), "val$" + li.name(), false, classToInvoke); meth.setActiveBody(src.getBody(meth, null)); meth.addTag(new soot.tagkit.SyntheticTag()); return meth; }
private static soot.SootMethod makeOuterThisAccessMethod(soot.SootClass classToInvoke) { String name = "access$" + soot.javaToJimple.InitialResolver.v().getNextPrivateAccessCounter() + "00"; ArrayList paramTypes = new ArrayList(); paramTypes.add(classToInvoke.getType()); soot.SootMethod meth = Scene.v().makeSootMethod(name, paramTypes, classToInvoke.getFieldByName("this$0").getType(), soot.Modifier.STATIC); classToInvoke.addMethod(meth); PrivateFieldAccMethodSource src = new PrivateFieldAccMethodSource(classToInvoke.getFieldByName("this$0").getType(), "this$0", classToInvoke.getFieldByName("this$0").isStatic(), classToInvoke); meth.setActiveBody(src.getBody(meth, null)); meth.addTag(new soot.tagkit.SyntheticTag()); return meth; }
private soot.SootMethod makeSuperAccessMethod(soot.SootClass classToInvoke, Object memberToAccess) { String name = "access$" + soot.javaToJimple.InitialResolver.v().getNextPrivateAccessCounter() + "00"; ArrayList paramTypes = new ArrayList(); paramTypes.add(classToInvoke.getType()); soot.SootMethod meth; soot.MethodSource src; if (memberToAccess instanceof polyglot.ast.Field) { polyglot.ast.Field fieldToAccess = (polyglot.ast.Field) memberToAccess; meth = Scene.v().makeSootMethod(name, paramTypes, Util.getSootType(fieldToAccess.type()), soot.Modifier.STATIC); PrivateFieldAccMethodSource fSrc = new PrivateFieldAccMethodSource(Util.getSootType(fieldToAccess.type()), fieldToAccess.name(), fieldToAccess.flags().isStatic(), ((soot.RefType) Util.getSootType(fieldToAccess.target().type())).getSootClass()); src = fSrc; } else if (memberToAccess instanceof polyglot.ast.Call) { polyglot.ast.Call methToAccess = (polyglot.ast.Call) memberToAccess; paramTypes.addAll(getSootParamsTypes(methToAccess)); meth = Scene.v().makeSootMethod(name, paramTypes, Util.getSootType(methToAccess.methodInstance().returnType()), soot.Modifier.STATIC); PrivateMethodAccMethodSource mSrc = new PrivateMethodAccMethodSource(methToAccess.methodInstance()); src = mSrc; } else { throw new RuntimeException("trying to access unhandled member type: " + memberToAccess); } classToInvoke.addMethod(meth); meth.setActiveBody(src.getBody(meth, null)); meth.addTag(new soot.tagkit.SyntheticTag()); return meth; }
/** * @ast method * @aspect EmitJimple * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddExtensions/JimpleBackend/EmitJimple.jrag:210 */ public void jimplify1phase2() { String name = name(); ArrayList parameters = new ArrayList(); ArrayList paramnames = new ArrayList(); for (int i = 0; i < getNumParameter(); i++) { parameters.add(getParameter(i).type().getSootType()); paramnames.add(getParameter(i).name()); } soot.Type returnType = type().getSootType(); int modifiers = sootTypeModifiers(); ArrayList throwtypes = new ArrayList(); for (int i = 0; i < getNumException(); i++) throwtypes.add(getException(i).type().getSootClassDecl()); String signature = SootMethod.getSubSignature(name, parameters, returnType); if (!hostType().getSootClassDecl().declaresMethod(signature)) { SootMethod m = Scene.v().makeSootMethod(name, parameters, returnType, modifiers, throwtypes); hostType().getSootClassDecl().addMethod(m); m.addTag(new soot.tagkit.ParamNamesTag(paramnames)); sootMethod = m; } else { sootMethod = hostType().getSootClassDecl().getMethod(signature); } addAttributes(); }
private SootMethod getOrCreateInitializer(SootClass sc, Set<SootField> alreadyInitialized) { SootMethod smInit; // Create a static initializer if we don't already have one smInit = sc.getMethodByNameUnsafe(SootMethod.staticInitializerName); if (smInit == null) { smInit = Scene.v().makeSootMethod(SootMethod.staticInitializerName, Collections.<Type>emptyList(), VoidType.v()); smInit.setActiveBody(Jimple.v().newBody(smInit)); sc.addMethod(smInit); smInit.setModifiers(Modifier.PUBLIC | Modifier.STATIC); } else if (smInit.isPhantom()) { return null; } else { smInit.retrieveActiveBody(); // We need to collect those variables that are already initialized // somewhere for (Unit u : smInit.getActiveBody().getUnits()) { Stmt s = (Stmt) u; for (ValueBox vb : s.getDefBoxes()) { if (vb.getValue() instanceof FieldRef) { alreadyInitialized.add(((FieldRef) vb.getValue()).getField()); } } } } return smInit; }
String signature = SootMethod.getSubSignature(name, parameters, returnType); if (!hostType().getSootClassDecl().declaresMethod(signature)) { SootMethod m = Scene.v().makeSootMethod(name, parameters, returnType, modifiers, throwtypes); hostType().getSootClassDecl().addMethod(m); m.addTag(new soot.tagkit.ParamNamesTag(paramnames));
private void createSootPreInitMethod() { // get a unique name for the method String uniqueName = getUniqueName(); // NOTICE WE ARE DEFINING ARGS AS SAME AS THE ORIGINAL METHOD newSootPreInitMethod = Scene.v().makeSootMethod(uniqueName, argsOneTypes, (new SootClass("DavaSuperHandler")).getType()); // set the declaring class of new method to be the originalSootClass newSootPreInitMethod.setDeclaringClass(originalSootClass); // set method to private and static newSootPreInitMethod.setModifiers(soot.Modifier.PRIVATE | soot.Modifier.STATIC); // initalize a new DavaBody, notice this causes all DavaBody vars to be // null newPreInitDavaBody = Dava.v().newBody(newSootPreInitMethod); // setting params is really important if you want the args to have // proper names in the new method newPreInitDavaBody.set_ParamMap(originalPMap); // set as activeBody newSootPreInitMethod.setActiveBody(newPreInitDavaBody); }
private soot.SootMethod addGetMethodAccessMeth(soot.SootClass conClass, polyglot.ast.Call call) { if ((InitialResolver.v().getPrivateMethodGetAccessMap() != null) && (InitialResolver.v().getPrivateMethodGetAccessMap() .containsKey(new polyglot.util.IdentityKey(call.methodInstance())))) { return InitialResolver.v().getPrivateMethodGetAccessMap().get(new polyglot.util.IdentityKey(call.methodInstance())); } String name = "access$" + soot.javaToJimple.InitialResolver.v().getNextPrivateAccessCounter() + "00"; ArrayList paramTypes = new ArrayList(); if (!call.methodInstance().flags().isStatic()) { // add this param type // paramTypes.add(Util.getSootType(call.methodInstance().container())); paramTypes.add(conClass.getType()); } ArrayList sootParamsTypes = getSootParamsTypes(call); paramTypes.addAll(sootParamsTypes); soot.SootMethod meth = Scene.v().makeSootMethod(name, paramTypes, Util.getSootType(call.methodInstance().returnType()), soot.Modifier.STATIC); PrivateMethodAccMethodSource pmams = new PrivateMethodAccMethodSource(call.methodInstance()); conClass.addMethod(meth); meth.setActiveBody(pmams.getBody(meth, null)); InitialResolver.v().addToPrivateMethodGetAccessMap(call, meth); meth.addTag(new soot.tagkit.SyntheticTag()); return meth; }
private soot.SootMethod addGetFieldAccessMeth(soot.SootClass conClass, polyglot.ast.Field field) { if ((InitialResolver.v().getPrivateFieldGetAccessMap() != null) && (InitialResolver.v().getPrivateFieldGetAccessMap() .containsKey(new polyglot.util.IdentityKey(field.fieldInstance())))) { return InitialResolver.v().getPrivateFieldGetAccessMap().get(new polyglot.util.IdentityKey(field.fieldInstance())); } String name = "access$" + soot.javaToJimple.InitialResolver.v().getNextPrivateAccessCounter() + "00"; ArrayList paramTypes = new ArrayList(); if (!field.flags().isStatic()) { // add this param type paramTypes.add(conClass.getType());// (soot.Local)getBaseLocal(field.target())); // paramTypes.add(Util.getSootType(field.target().type())); } soot.SootMethod meth = Scene.v().makeSootMethod(name, paramTypes, Util.getSootType(field.type()), soot.Modifier.STATIC); PrivateFieldAccMethodSource pfams = new PrivateFieldAccMethodSource(Util.getSootType(field.type()), field.name(), field.flags().isStatic(), conClass); conClass.addMethod(meth); meth.setActiveBody(pfams.getBody(meth, null)); InitialResolver.v().addToPrivateFieldGetAccessMap(field, meth); meth.addTag(new soot.tagkit.SyntheticTag()); return meth; }
private soot.SootMethod addSetAccessMeth(soot.SootClass conClass, polyglot.ast.Field field, soot.Value param) { if ((InitialResolver.v().getPrivateFieldSetAccessMap() != null) && (InitialResolver.v().getPrivateFieldSetAccessMap() .containsKey(new polyglot.util.IdentityKey(field.fieldInstance())))) { return InitialResolver.v().getPrivateFieldSetAccessMap().get(new polyglot.util.IdentityKey(field.fieldInstance())); } String name = "access$" + soot.javaToJimple.InitialResolver.v().getNextPrivateAccessCounter() + "00"; ArrayList paramTypes = new ArrayList(); if (!field.flags().isStatic()) { // add this param type paramTypes.add(conClass.getType()); // paramTypes.add(Util.getSootType(field.target().type())); } soot.Type retType; paramTypes.add(Util.getSootType(field.type())); retType = Util.getSootType(field.type()); /* * if (param.getType() instanceof soot.NullType){ paramTypes.add(soot.RefType.v("java.lang.Object")); retType = * soot.RefType.v("java.lang.Object"); } else { paramTypes.add(param.getType()); retType = param.getType(); } */ soot.SootMethod meth = Scene.v().makeSootMethod(name, paramTypes, retType, soot.Modifier.STATIC); PrivateFieldSetMethodSource pfsms = new PrivateFieldSetMethodSource(Util.getSootType(field.type()), field.name(), field.flags().isStatic()); conClass.addMethod(meth); meth.setActiveBody(pfsms.getBody(meth, null)); InitialResolver.v().addToPrivateFieldSetAccessMap(field, meth); meth.addTag(new soot.tagkit.SyntheticTag()); return meth; }
/** * Retrieve the SootMethod equivalent of this method * * @return the SootMethod of this method */ public SootMethod makeSootMethod(final Method method) { int accessFlags = method.getAccessFlags(); // get the name of the method String name = method.getName(); List<SootClass> thrownExceptions = getThrownExceptions(method); List<Type> parameterTypes = getParameterTypes(method); // retrieve the return type of this method Type returnType = DexType.toSoot(method.getReturnType()); // Build soot method by all available parameters SootMethod sm = declaringClass.getMethodUnsafe(name, parameterTypes, returnType); if (sm == null) { sm = Scene.v().makeSootMethod(name, parameterTypes, returnType, accessFlags, thrownExceptions); } // if the method is abstract or native, no code needs to be transformed int flags = method.getAccessFlags(); if (Modifier.isAbstract(flags) || Modifier.isNative(flags)) { return sm; } if (Options.v().oaat() && declaringClass.resolvingLevel() <= SootClass.SIGNATURES) { return sm; } // sets the method source by adding its body as the active body sm.setSource(createMethodSource(method)); return sm; }
final Body body; if (addStaticInitializer) { final SootMethod staticInitializerMethod = Scene.v().makeSootMethod(SootMethod.staticInitializerName, Collections.emptyList(), VoidType.v(), Modifier.STATIC); sootClass.addMethod(staticInitializerMethod);