private int addJimpleLnTags(int lnNum, SootMethod meth) { meth.addTag(new JimpleLineNumberTag(lnNum)); lnNum++; return lnNum; }
@Override public void visitEnd() { method.addTag(new AnnotationDefaultTag(elems.get(0))); } };
private void addQualifierRefToInit(polyglot.types.Type type) { soot.Type sootType = Util.getSootType(type); Iterator it = sootClass.getMethods().iterator(); while (it.hasNext()) { soot.SootMethod meth = (soot.SootMethod) it.next(); if (meth.getName().equals("<init>")) { List newParams = new ArrayList(); newParams.add(sootType); newParams.addAll(meth.getParameterTypes()); meth.setParameterTypes(newParams); meth.addTag(new soot.tagkit.QualifyingTag()); } } }
protected void internalTransform(String phaseName, Map options) { // make list of all unreachable methods ArrayList<SootMethod> methodList = new ArrayList<SootMethod>(); Iterator getClassesIt = Scene.v().getApplicationClasses().iterator(); while (getClassesIt.hasNext()) { SootClass appClass = (SootClass) getClassesIt.next(); Iterator getMethodsIt = appClass.getMethods().iterator(); while (getMethodsIt.hasNext()) { SootMethod method = (SootMethod) getMethodsIt.next(); // System.out.println("adding method: "+method); if (!Scene.v().getReachableMethods().contains(method)) { methodList.add(method); } } } // tag unused methods Iterator<SootMethod> unusedIt = methodList.iterator(); while (unusedIt.hasNext()) { SootMethod unusedMethod = unusedIt.next(); unusedMethod.addTag(new StringTag("Method " + unusedMethod.getName() + " is not reachable!", "Unreachable Methods")); unusedMethod.addTag(new ColorTag(255, 0, 0, true, "Unreachable Methods")); // System.out.println("tagged method: "+unusedMethod); } }
/** * @ast method * @aspect AnnotationsCodegen * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddExtensions/Jimple1.5Backend/AnnotationsCodegen.jrag:293 */ public void addAttributes() { super.addAttributes(); // 4.8.19 if(hasDefaultValue()) { ArrayList elements = new ArrayList(1); getDefaultValue().appendAsAttributeTo(elements, "default"); soot.tagkit.AnnotationDefaultTag tag = new soot.tagkit.AnnotationDefaultTag((soot.tagkit.AnnotationElem)elements.get(0)); sootMethod.addTag(tag); } } /**
private void addOuterClassThisRefToInit(polyglot.types.Type outerType) { soot.Type outerSootType = Util.getSootType(outerType); Iterator it = sootClass.getMethods().iterator(); while (it.hasNext()) { soot.SootMethod meth = (soot.SootMethod) it.next(); if (meth.getName().equals("<init>")) { List newParams = new ArrayList(); newParams.add(outerSootType); newParams.addAll(meth.getParameterTypes()); meth.setParameterTypes(newParams); meth.addTag(new soot.tagkit.EnclosingTag()); if (InitialResolver.v().getHasOuterRefInInit() == null) { InitialResolver.v().setHasOuterRefInInit(new ArrayList()); } InitialResolver.v().getHasOuterRefInInit().add(meth.getDeclaringClass().getType()); } } }
/** * @ast method * @aspect AnnotationsCodegen * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddExtensions/Jimple1.5Backend/AnnotationsCodegen.jrag:57 */ public void addAttributes() { super.addAttributes(); ArrayList c = new ArrayList(); getModifiers().addRuntimeVisibleAnnotationsAttribute(c); getModifiers().addRuntimeInvisibleAnnotationsAttribute(c); addRuntimeVisibleParameterAnnotationsAttribute(c); addRuntimeInvisibleParameterAnnotationsAttribute(c); addSourceLevelParameterAnnotationsAttribute(c); getModifiers().addSourceOnlyAnnotations(c); for (Iterator iter = c.iterator(); iter.hasNext();) { soot.tagkit.Tag tag = (soot.tagkit.Tag) iter.next(); sootMethod.addTag(tag); } }
/** * @ast method * @aspect AnnotationsCodegen * @declaredat /Users/eric/Documents/workspaces/clara-soot/JastAddExtensions/Jimple1.5Backend/AnnotationsCodegen.jrag:43 */ public void addAttributes() { super.addAttributes(); ArrayList c = new ArrayList(); getModifiers().addRuntimeVisibleAnnotationsAttribute(c); getModifiers().addRuntimeInvisibleAnnotationsAttribute(c); addRuntimeVisibleParameterAnnotationsAttribute(c); addRuntimeInvisibleParameterAnnotationsAttribute(c); addSourceLevelParameterAnnotationsAttribute(c); getModifiers().addSourceOnlyAnnotations(c); for (Iterator iter = c.iterator(); iter.hasNext();) { soot.tagkit.Tag tag = (soot.tagkit.Tag) iter.next(); sootMethod.addTag(tag); } }
@Override public void visitEnd() { super.visitEnd(); if (visibleParamAnnotations != null) { VisibilityParameterAnnotationTag tag = new VisibilityParameterAnnotationTag(visibleParamAnnotations.length, AnnotationConstants.RUNTIME_VISIBLE); for (VisibilityAnnotationTag vat : visibleParamAnnotations) { tag.addVisibilityAnnotation(vat); } method.addTag(tag); } if (invisibleParamAnnotations != null) { VisibilityParameterAnnotationTag tag = new VisibilityParameterAnnotationTag(invisibleParamAnnotations.length, AnnotationConstants.RUNTIME_INVISIBLE); for (VisibilityAnnotationTag vat : invisibleParamAnnotations) { tag.addVisibilityAnnotation(vat); } method.addTag(tag); } if (method.isConcrete()) { method.setSource(new AsmMethodSource(maxLocals, instructions, localVariables, tryCatchBlocks)); } } }
@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; }
src = callEdge.srcUnit(); m.addTag(new LinkTag( "CallGraph: Source Type: " + callEdge.kind() + " Source Method/Context: " + callEdge.getSrc().toString(), src, methodCaller.getDeclaringClass().getName(), "Call Graph"));
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; }
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 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; }
SootMethod m = Scene.v().makeSootMethod(name, parameters, returnType, modifiers, throwtypes); hostType().getSootClassDecl().addMethod(m); m.addTag(new soot.tagkit.ParamNamesTag(paramnames)); sootMethod = m; } else {
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 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 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; }