/** * Returns the signature of this method in the format in which it appears in bytecode (eg. [Ljava/lang/Object instead of * java.lang.Object[]). */ public String getBytecodeSignature() { String name = getName(); StringBuffer buffer = new StringBuffer(); buffer.append("<" + Scene.v().quotedNameOf(getDeclaringClass().getName()) + ": "); buffer.append(name); buffer.append(AbstractJasminClass.jasminDescriptorOf(makeRef())); buffer.append(">"); return buffer.toString().intern(); }
public void convert(DavaBody body) { for (AugmentedStmt mas : body.get_MonitorFacts()) { MonitorStmt ms = (MonitorStmt) mas.get_Stmt(); body.addToImportList("soot.dava.toolkits.base.DavaMonitor.DavaMonitor"); ArrayList arg = new ArrayList(); arg.add(ms.getOp()); if (ms instanceof EnterMonitorStmt) { mas.set_Stmt(new GInvokeStmt(new DVirtualInvokeExpr(new DStaticInvokeExpr(v.makeRef(), new ArrayList()), enter.makeRef(), arg, new HashSet<Object>()))); } else { mas.set_Stmt(new GInvokeStmt(new DVirtualInvokeExpr(new DStaticInvokeExpr(v.makeRef(), new ArrayList()), exit.makeRef(), arg, new HashSet<Object>()))); } } } }
public boolean changeOriginalAST() { // originalDavaBody has to be changed // fix up the call within the constructorUnit....the args should be // argsOne followed by a method call to preInit if (originalConstructorExpr == null) { // hmm that means there was no call to super in the original code // System.out.println("originalConstructorExpr is null"); return false; } List thisArgList = new ArrayList(); thisArgList.addAll(argsOneValues); DStaticInvokeExpr newInvokeExpr = new DStaticInvokeExpr(newSootPreInitMethod.makeRef(), argsOneValues); thisArgList.add(newInvokeExpr); // the methodRef of themethod to be called is the new constructor we // created InstanceInvokeExpr tempExpr = new DSpecialInvokeExpr(originalConstructorExpr.getBase(), newConstructor.makeRef(), thisArgList); originalDavaBody.set_ConstructorExpr(tempExpr); // create Invoke Stmt with tempExpr as the expression GInvokeStmt s = new GInvokeStmt(tempExpr); originalDavaBody.set_ConstructorUnit(s); // originalASTMethod has to be made empty originalASTMethod.setDeclarations(new ASTStatementSequenceNode(new ArrayList<AugmentedStmt>())); originalASTMethod.replaceBody(new ArrayList<Object>()); return true; }
/** * P box = P.valueOf(fromLocal); * * @param fromLocal * primitive * @param jb * @param us * @return */ private Local box(Local fromLocal, JimpleBody jb, PatchingChain<Unit> us, LocalGenerator lc) { PrimType primitiveType = (PrimType) fromLocal.getType(); RefType wrapperType = primitiveType.boxedType(); SootMethod valueOfMethod = wrapper.valueOf.get(primitiveType); Local lBox = lc.generateLocal(wrapperType); if (lBox == null || valueOfMethod == null || us == null) { throw new NullPointerException(String.format("%s,%s,%s,%s", valueOfMethod, primitiveType, wrapper.valueOf.entrySet(), wrapper.valueOf.get(primitiveType))); } us.add(Jimple.v().newAssignStmt(lBox, Jimple.v().newStaticInvokeExpr(valueOfMethod.makeRef(), fromLocal))); return lBox; }
/** * p unbox = fromLocal.pValue(); * * @param fromLocal * boxed * @param jb * @param us * @return */ private Local unbox(Local fromLocal, JimpleBody jb, PatchingChain<Unit> us, LocalGenerator lc) { RefType wrapperType = (RefType) fromLocal.getType(); PrimType primitiveType = wrapper.wrapperTypes.get(wrapperType); SootMethod primitiveValueMethod = wrapper.primitiveValue.get(wrapperType); Local lUnbox = lc.generateLocal(primitiveType); us.add(Jimple.v().newAssignStmt(lUnbox, Jimple.v().newVirtualInvokeExpr(fromLocal, primitiveValueMethod.makeRef()))); return lUnbox; }
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(); }
@Override protected soot.Local handlePrivateFieldSet(polyglot.ast.Expr expr, soot.Value right, soot.Value base) { // in normal j2j its always a field (and checked before call) // only has an expr for param for extensibility polyglot.ast.Field fLeft = (polyglot.ast.Field) expr; soot.SootClass containClass = ((soot.RefType) Util.getSootType(fLeft.target().type())).getSootClass(); soot.SootMethod methToUse = addSetAccessMeth(containClass, fLeft, right); ArrayList params = new ArrayList(); if (!fLeft.flags().isStatic()) { // this is the this ref if needed // params.add(getThis(Util.getSootType(fLeft.target().type()))); params.add(base); } params.add(right); soot.jimple.InvokeExpr invoke = soot.jimple.Jimple.v().newStaticInvokeExpr(methToUse.makeRef(), params); soot.Local retLocal = lg.generateLocal(right.getType()); soot.jimple.AssignStmt assignStmt = soot.jimple.Jimple.v().newAssignStmt(retLocal, invoke); body.getUnits().add(assignStmt); return retLocal; }
private void loadBooleanValue(PatchingChain<Unit> units, SootField f, Unit insert) { units.insertBefore(Baf.v().newStaticGetInst(f.makeRef()), insert); if (f.getType() instanceof RefType) { SootMethod boolInit = ((RefType) f.getType()).getSootClass().getMethod("boolean booleanValue()"); units.insertBefore(Baf.v().newVirtualInvokeInst(boolInit.makeRef()), insert); } }
public static soot.Local getThisGivenOuter(soot.Type sootType, HashMap getThisMap, soot.Body body, LocalGenerator lg, soot.Local t2) { if (InitialResolver.v().hierarchy() == null) { InitialResolver.v().hierarchy(new soot.FastHierarchy()); } soot.FastHierarchy fh = InitialResolver.v().hierarchy(); while (!fh.canStoreType(t2.getType(), sootType)) { soot.SootClass classToInvoke = ((soot.RefType) t2.getType()).getSootClass(); // make an access method and add it to that class for accessing // its private this$0 field soot.SootMethod methToInvoke = makeOuterThisAccessMethod(classToInvoke); // generate a local that corresponds to the invoke of that meth soot.Local t3 = lg.generateLocal(methToInvoke.getReturnType()); ArrayList methParams = new ArrayList(); methParams.add(t2); soot.Local res = getPrivateAccessFieldInvoke(methToInvoke.makeRef(), methParams, body, lg); soot.jimple.AssignStmt assign = soot.jimple.Jimple.v().newAssignStmt(t3, res); body.getUnits().add(assign); t2 = t3; } getThisMap.put(sootType, t2); return t2; }
.getMethod("<init>", Collections.<Type>singletonList(RefType.v("java.lang.String"))).makeRef(); SpecialInvokeExpr constructorInvokeExpr = Jimple.v().newSpecialInvokeExpr(exceptionLocal, cref, StringConstant.v(guard.message)); .getSootClass("java.lang.Throwable").getMethod("printStackTrace", Collections.<Type>emptyList()).makeRef()); InvokeStmt printStackTraceStmt = Jimple.v().newInvokeStmt(printStackTraceExpr); body.getUnits().insertAfter(printStackTraceStmt, initStmt);
static Stmt addThrowAfter(JimpleBody b, Stmt target) { Chain<Unit> units = b.getUnits(); Collection<Local> locals = b.getLocals(); int i = 0; // Bah! boolean canAddI = false; do { canAddI = true; Iterator<Local> localIt = locals.iterator(); while (localIt.hasNext()) { Local l = (Local) localIt.next(); if (l.getName().equals("__throwee" + i)) { canAddI = false; } } if (!canAddI) { i++; } } while (!canAddI); Local l = Jimple.v().newLocal("__throwee" + i, RefType.v("java.lang.NullPointerException")); b.getLocals().add(l); Stmt newStmt = Jimple.v().newAssignStmt(l, Jimple.v().newNewExpr(RefType.v("java.lang.NullPointerException"))); Stmt invStmt = Jimple.v().newInvokeStmt(Jimple.v().newSpecialInvokeExpr(l, Scene.v().getMethod("<java.lang.NullPointerException: void <init>()>").makeRef())); Stmt throwStmt = Jimple.v().newThrowStmt(l); units.insertAfter(newStmt, target); units.insertAfter(invStmt, newStmt); units.insertAfter(throwStmt, invStmt); return newStmt; }
private soot.Local getSpecialSuperQualifierLocal(polyglot.ast.Expr expr) { soot.SootClass classToInvoke; ArrayList methodParams = new ArrayList(); if (expr instanceof polyglot.ast.Call) { polyglot.ast.Special target = (polyglot.ast.Special) ((polyglot.ast.Call) expr).target(); classToInvoke = ((soot.RefType) Util.getSootType(target.qualifier().type())).getSootClass(); methodParams = getSootParams((polyglot.ast.Call) expr); } else if (expr instanceof polyglot.ast.Field) { polyglot.ast.Special target = (polyglot.ast.Special) ((polyglot.ast.Field) expr).target(); classToInvoke = ((soot.RefType) Util.getSootType(target.qualifier().type())).getSootClass(); } else { throw new RuntimeException("Trying to create special super qualifier for: " + expr + " which is not a field or call"); } // make an access method soot.SootMethod methToInvoke = makeSuperAccessMethod(classToInvoke, expr); // invoke it soot.Local classToInvokeLocal = Util.getThis(classToInvoke.getType(), body, getThisMap, lg); methodParams.add(0, classToInvokeLocal); soot.jimple.InvokeExpr invokeExpr = soot.jimple.Jimple.v().newStaticInvokeExpr(methToInvoke.makeRef(), methodParams); // return the local of return type if not void if (!methToInvoke.getReturnType().equals(soot.VoidType.v())) { soot.Local retLocal = lg.generateLocal(methToInvoke.getReturnType()); soot.jimple.AssignStmt stmt = soot.jimple.Jimple.v().newAssignStmt(retLocal, invokeExpr); body.getUnits().add(stmt); return retLocal; } else { body.getUnits().add(soot.jimple.Jimple.v().newInvokeStmt(invokeExpr)); return null; } }
units.insertBefore(ifStmt = Jimple.v().newIfStmt(Jimple.v().newNeExpr(l, NullConstant.v()), target), target); units.insertBefore(Jimple.v().newAssignStmt(l, Jimple.v().newStaticInvokeExpr(getClassFetcherFor(sc).makeRef(), Arrays.asList(new Value[] { StringConstant.v(sc.getName()) }))), target); units.insertBefore(Jimple.v().newAssignStmt(Jimple.v().newStaticFieldRef(classCacher.makeRef()), l), target);
methParams.add(getThis(currentClass.getType())); soot.Local res = Util.getPrivateAccessFieldInvoke(methToInvoke.makeRef(), methParams, body, lg); return res;
/** * @ast method * @aspect Expressions * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddExtensions/JimpleBackend/Expressions.jrag:557 */ private soot.Value emitInnerMemberEnclosing(Body b, TypeDecl innerClass) { if(hasPrevExpr()) { Local base = asLocal(b, prevExpr().eval(b)); b.setLine(this); b.add(b.newInvokeStmt( b.newVirtualInvokeExpr( base, Scene.v().getMethod("<java.lang.Object: java.lang.Class getClass()>").makeRef(), this ), this )); return base; } else { TypeDecl enclosing = hostType(); while(!enclosing.hasType(innerClass.name())) enclosing = enclosing.enclosingType(); return emitThis(b, enclosing); } } /**
args.add(((InstanceFieldRef) ref).getBase()); InvokeExpr newExpr = Jimple.v().newStaticInvokeExpr(accessor.makeRef(), args);
InvokeExpr newExpr = Jimple.v().newStaticInvokeExpr(accessor.makeRef(), args);
units.addFirst(Jimple.v().newAssignStmt(Jimple.v().newStaticFieldRef(field.makeRef()), bool)); units.addFirst(Jimple.v().newInvokeStmt( Jimple.v().newSpecialInvokeExpr(bool, booleanWrapperConstructor.makeRef(), IntConstant.v(value ? 1 : 0)))); units.addFirst(Jimple.v().newAssignStmt(bool, Jimple.v().newNewExpr(booleanWrapperRefType)));