private void addProcedureToClass(soot.SootMethod method) { sootClass.addMethod(method); }
/** * Changes the set of parameter types of this method. */ public synchronized void setParameterTypes(List<Type> l) { boolean wasDeclared = isDeclared; SootClass oldDeclaringClass = declaringClass; if (wasDeclared) { oldDeclaringClass.removeMethod(this); } this.parameterTypes = l.toArray(new Type[l.size()]); subSig = null; sig = null; subsignature = Scene.v().getSubSigNumberer().findOrAdd(getSubSignature()); if (wasDeclared) { oldDeclaringClass.addMethod(this); } }
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); }
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); }
private void addDispatch(String name, SootClass tclass, MethodType implMethodType, MethodType instantiatedMethodType, List<SootField> capFields, MethodHandle implMethod) { ThunkMethodSource ms = new ThunkMethodSource(capFields, implMethodType, implMethod, instantiatedMethodType); SootMethod m = new SootMethod(name, implMethodType.getParameterTypes(), implMethodType.getReturnType(), Modifier.PUBLIC); tclass.addMethod(m); m.setSource(ms); }
/** Sets the name of this method. */ public synchronized void setName(String name) { boolean wasDeclared = isDeclared; SootClass oldDeclaringClass = declaringClass; if (wasDeclared) { oldDeclaringClass.removeMethod(this); } this.name = name; subSig = null; sig = null; subsignature = Scene.v().getSubSigNumberer().findOrAdd(getSubSignature()); if (wasDeclared) { oldDeclaringClass.addMethod(this); } }
/** Sets the return type of this method. */ public synchronized void setReturnType(Type t) { boolean wasDeclared = isDeclared; SootClass oldDeclaringClass = declaringClass; if (wasDeclared) { oldDeclaringClass.removeMethod(this); } returnType = t; subSig = null; sig = null; subsignature = Scene.v().getSubSigNumberer().findOrAdd(getSubSignature()); if (wasDeclared) { oldDeclaringClass.addMethod(this); } }
/** * @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(); }
mSootClass.addMethod(method);
/** * Loads a single method from a dex file * * @param method * The method to load * @param declaringClass * The class that declares the method to load * @param annotations * The worker object for handling annotations * @param dexMethodFactory * The factory method for creating dex methods */ protected void loadMethod(Method method, SootClass declaringClass, DexAnnotation annotations, DexMethod dexMethodFactory) { SootMethod sm = dexMethodFactory.makeSootMethod(method); if (declaringClass.declaresMethod(sm.getName(), sm.getParameterTypes(), sm.getReturnType())) { return; } declaringClass.addMethod(sm); annotations.handleMethodAnnotation(sm, method); }
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; }
addToClass.addMethod(sootMethod); sootMethod.addTag(new soot.tagkit.SyntheticTag());
/** * @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; }
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; }
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; }
final SootMethod staticInitializerMethod = Scene.v().makeSootMethod(SootMethod.staticInitializerName, Collections.emptyList(), VoidType.v(), Modifier.STATIC); sootClass.addMethod(staticInitializerMethod); body = Jimple.v().newBody(staticInitializerMethod); staticInitializerMethod.setActiveBody(body);