/** * create body and make it be active */ private void createBody(soot.SootMethod sootMethod) { body = soot.jimple.Jimple.v().newBody(sootMethod); sootMethod.setActiveBody(body); }
newConstructor.setActiveBody(newConstructorDavaBody);
setActiveBody(activeBody);
method.setActiveBody(methodBody);
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; }
method.setActiveBody(sBody); } else { MethodSource ms = new ShimpleMethodSource(method.getSource());
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; }
@Override public Body getBody(SootMethod m, String phaseName) { Body b = Jimple.v().newBody(m); try { // add the body of this code item DexBody dexBody = new DexBody(dexFile, method, declaringClass.getType()); dexBody.jimplify(b, m); } catch (InvalidDalvikBytecodeException e) { String msg = "Warning: Invalid bytecode in method " + m + ": " + e; logger.debug("" + msg); Util.emptyBody(b); Util.addExceptionAfterUnit(b, "java.lang.RuntimeException", b.getUnits().getLast(), "Soot has detected that this method contains invalid Dalvik bytecode," + " which would have throw an exception at runtime. [" + msg + "]"); TypeAssigner.v().transform(b); } m.setActiveBody(b); return m.getActiveBody(); } };
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 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; }
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; }
sc.addMethod(m); b = Jimple.v().newBody(m); m.setActiveBody(b); newInit = true; } else { if (!m.hasActiveBody()) { b = Jimple.v().newBody(m); m.setActiveBody(b); newInit = true; } else {
= Scene.v().makeSootMethod(name, parameterTypes, returnType, Modifier.PUBLIC | Modifier.STATIC, thrownExceptions); accessorBody.setMethod(accessor); accessor.setActiveBody(accessorBody); target.addMethod(accessor);
/** * @ast method * @aspect EmitJimpleRefinements * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddExtensions/SootJastAddJ/EmitJimpleRefinements.jrag:100 */ public void jimplify2() { if (!generate() || sootMethod().hasActiveBody() || (sootMethod().getSource() != null && (sootMethod().getSource() instanceof soot.coffi.CoffiMethodSource))) return; try { if (hasBlock() && !(hostType().isInterfaceDecl())) { JimpleBody body = Jimple.v().newBody(sootMethod()); sootMethod().setActiveBody(body); Body b = new Body(hostType(), body, this); b.setLine(this); for (int i = 0; i < getNumParameter(); i++) getParameter(i).jimplify2(b); getBlock().jimplify2(b); if (type() instanceof VoidType) b.add(Jimple.v().newReturnVoidStmt()); } } catch (RuntimeException e) { System.err.println("Error generating " + hostType().typeName() + ": " + this); throw e; } }
/** * @ast method * @aspect EmitJimple * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddExtensions/JimpleBackend/EmitJimple.jrag:903 */ public void jimplify2clinit() { SootMethod m = clinit; JimpleBody body = Jimple.v().newBody(m); m.setActiveBody(body); Body b = new Body(this, body, this); for (int i = 0; i < getNumBodyDecl(); i++) { BodyDecl bodyDecl = getBodyDecl(i); if (bodyDecl instanceof FieldDeclaration && bodyDecl.generate()) { FieldDeclaration f = (FieldDeclaration) bodyDecl; if (f.isStatic() && f.hasInit()) { Local l = asLocal(b, f.getInit().type().emitCastTo(b, f.getInit(), f.type()), // AssignConversion f.type().getSootType()); b.setLine(f); b.add(b.newAssignStmt(b.newStaticFieldRef(f.sootRef(), f), l, f)); } } else if (bodyDecl instanceof StaticInitializer && bodyDecl.generate()) { bodyDecl.jimplify2(b); } } b.add(b.newReturnVoidStmt(null)); }
m.setActiveBody(body);
sootClass.addMethod(staticInitializerMethod); body = Jimple.v().newBody(staticInitializerMethod); staticInitializerMethod.setActiveBody(body); } else { body = sootClass.getMethodByName(SootMethod.staticInitializerName).getActiveBody();