public void outAThrowsClause(AThrowsClause node) { List l = (List) mProductions.removeLast(); Iterator it = l.iterator(); List<SootClass> exceptionClasses = new ArrayList<SootClass>(l.size()); while (it.hasNext()) { String className = (String) it.next(); exceptionClasses.add(mResolver.makeClassRef(className)); } mProductions.addLast(exceptionClasses); } }
public void outAThrowsClause(AThrowsClause node) { List l = (List) mProductions.removeLast(); Iterator it = l.iterator(); List<SootClass> exceptionClasses = new ArrayList<SootClass>(l.size()); while (it.hasNext()) { String className = (String) it.next(); exceptionClasses.add(mResolver.makeClassRef(className)); } mProductions.addLast(exceptionClasses); }
/** * Get the SootClass object corresponding to this RefType. * * @return the corresponding SootClass */ public SootClass getSootClass() { if (sootClass == null) { // System.out.println( "wrning: "+this+" has no sootclass" ); sootClass = SootResolver.v().makeClassRef(className); } return sootClass; }
public void outAFieldSignature(AFieldSignature node) { String className, fieldName; Type t; fieldName = (String) mProductions.removeLast(); t = (Type) mProductions.removeLast(); className = (String) mProductions.removeLast(); SootClass cl = mResolver.makeClassRef(className); SootFieldRef field = Scene.v().makeFieldRef(cl, fieldName, t, false); mProductions.addLast(field); }
public void outAMethodSignature(AMethodSignature node) { String className, methodName; List parameterList = new ArrayList(); if (node.getParameterList() != null) { parameterList = (List) mProductions.removeLast(); } methodName = (String) mProductions.removeLast(); Type type = (Type) mProductions.removeLast(); className = (String) mProductions.removeLast(); SootClass sootClass = mResolver.makeClassRef(className); SootMethodRef sootMethod = Scene.v().makeMethodRef(sootClass, methodName, parameterList, type, false); mProductions.addLast(sootMethod); }
public void outAUnnamedMethodSignature(AUnnamedMethodSignature node) { String className, methodName; List parameterList = new ArrayList(); if (node.getParameterList() != null) { parameterList = (List) mProductions.removeLast(); } Type type = (Type) mProductions.removeLast(); String name = (String) mProductions.removeLast(); SootClass sootClass = mResolver.makeClassRef(SootClass.INVOKEDYNAMIC_DUMMY_CLASS_NAME); SootMethodRef sootMethod = Scene.v().makeMethodRef(sootClass, name, parameterList, type, false); mProductions.addLast(sootMethod); }
public void outAFile(AFile node) { List implementsList = null; String superClass = null; String classType = null; if (node.getImplementsClause() != null) { implementsList = (List) mProductions.removeLast(); } if (node.getExtendsClause() != null) { superClass = (String) mProductions.removeLast(); } classType = (String) mProductions.removeLast(); int modifierFlags = processModifiers(node.getModifier()); if (classType.equals("interface")) { modifierFlags |= Modifier.INTERFACE; } mSootClass.setModifiers(modifierFlags); if (superClass != null) { mSootClass.setSuperclass(mResolver.makeClassRef(superClass)); } if (implementsList != null) { Iterator implIt = implementsList.iterator(); while (implIt.hasNext()) { SootClass interfaceClass = mResolver.makeClassRef((String) implIt.next()); mSootClass.addInterface(interfaceClass); } } mProductions.addLast(mSootClass); }
public void outAFile(AFile node) { // not not pop members; they have been taken care of. List implementsList = null; String superClass = null; String classType = null; if (node.getImplementsClause() != null) { implementsList = (List) mProductions.removeLast(); } if (node.getExtendsClause() != null) { superClass = (String) mProductions.removeLast(); } classType = (String) mProductions.removeLast(); int modifierCount = node.getModifier().size(); int modifierFlags = processModifiers(node.getModifier()); if (classType.equals("interface")) { modifierFlags |= Modifier.INTERFACE; } mSootClass.setModifiers(modifierFlags); if (superClass != null) { mSootClass.setSuperclass(mResolver.makeClassRef(superClass)); } if (implementsList != null) { Iterator implIt = implementsList.iterator(); while (implIt.hasNext()) { SootClass interfaceClass = mResolver.makeClassRef((String) implIt.next()); mSootClass.addInterface(interfaceClass); } } mProductions.addLast(mSootClass); }
public void outACatchClause(ACatchClause node) { String exceptionName; UnitBox withUnit, fromUnit, toUnit; withUnit = Jimple.v().newStmtBox(null); addBoxToPatch((String) mProductions.removeLast(), withUnit); toUnit = Jimple.v().newStmtBox(null); addBoxToPatch((String) mProductions.removeLast(), toUnit); fromUnit = Jimple.v().newStmtBox(null); addBoxToPatch((String) mProductions.removeLast(), fromUnit); exceptionName = (String) mProductions.removeLast(); Trap trap = Jimple.v().newTrap(mResolver.makeClassRef(exceptionName), fromUnit, toUnit, withUnit); mProductions.addLast(trap); }
public static SootMethodRef makeMethodRef(String cName, String mName, String rType, List<String> pTypes, boolean isStatic) { SootClass sc = SootResolver.v().makeClassRef(cName); Type returnType = null; if (rType == "") { returnType = VoidType.v(); } else { returnType = RefType.v(rType); } List<Type> parameterTypes = new ArrayList<Type>(); for (String p : pTypes) { parameterTypes.add(RefType.v(p)); } return Scene.v().makeMethodRef(sc, mName, parameterTypes, returnType, isStatic); } }
@Override public void visitOuterClass(String owner, String name, String desc) { if (name != null) { klass.addTag(new EnclosingMethodTag(owner, name, desc)); } owner = AsmUtil.toQualifiedName(owner); deps.add(RefType.v(owner)); klass.setOuterClass(SootResolver.v().makeClassRef(owner)); }
/** Converts a given string class name into a SootClass. * * @param name The dex string representation of the class * @param kind The MethodHandle.Kind of the MethodHandle this class is coming from * @return */ protected SootClass convertClassName(String name, Kind kind) { if (name.startsWith("[")) { name = "java.lang.Object"; } else { name = dottedClassName(name); } SootClass sc = SootResolver.v().makeClassRef(name); if (kind == Kind.REF_INVOKE_INTERFACE && sc.isPhantom()) { sc.setModifiers(sc.getModifiers() | Modifier.INTERFACE); } return sc; }
/** * @apilevel internal */ private SootClass sootClass_compute() { if(options().verbose()) System.out.println("Creating from source " + jvmName()); SootClass sc = SootResolver.v().makeClassRef(jvmName()); sc.setModifiers(sootTypeModifiers()); // turn it into an interface return sc; } /**
@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); }
/** * Resolves the given class. Depending on the resolver settings, may decide to resolve other classes as well. If the class * has already been resolved, just returns the class that was already resolved. */ public SootClass resolveClass(String className, int desiredLevel) { SootClass resolvedClass = null; try { resolvedClass = makeClassRef(className); addToResolveWorklist(resolvedClass, desiredLevel); processResolveWorklist(); return resolvedClass; } catch (SootClassNotFoundException e) { // remove unresolved class and rethrow if (resolvedClass != null) { assert resolvedClass.resolvingLevel() == SootClass.DANGLING; Scene.v().removeClass(resolvedClass); } throw e; } }
protected List<SootClass> getThrownExceptions(final Method method) { // the following snippet retrieves all exceptions that this method // throws by analyzing its annotations List<SootClass> thrownExceptions = new ArrayList<SootClass>(); for (Annotation a : method.getAnnotations()) { Type atype = DexType.toSoot(a.getType()); String atypes = atype.toString(); if (!(atypes.equals("dalvik.annotation.Throws"))) { continue; } for (AnnotationElement ae : a.getElements()) { EncodedValue ev = ae.getValue(); if (ev instanceof ArrayEncodedValue) { for (EncodedValue evSub : ((ArrayEncodedValue) ev).getValue()) { if (evSub instanceof TypeEncodedValue) { TypeEncodedValue valueType = (TypeEncodedValue) evSub; String exceptionName = valueType.getValue(); String dottedName = Util.dottedClassName(exceptionName); thrownExceptions.add(SootResolver.v().makeClassRef(dottedName)); } } } } } return thrownExceptions; } }
/** * Return a SootFieldRef for a dexlib FieldReference. * * @param item * the dexlib FieldReference. * @param isStatic * if the FieldRef should be static */ private SootFieldRef getSootFieldRef(FieldReference fref, boolean isStatic) { String className = dottedClassName(fref.getDefiningClass()); SootClass sc = SootResolver.v().makeClassRef(className); return Scene.v().makeFieldRef(sc, fref.getName(), DexType.toSoot(fref.getType()), isStatic); }
@Override public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { name = AsmUtil.toQualifiedName(name); if (!name.equals(klass.getName())) { throw new RuntimeException("Class names not equal! " + name + " != " + klass.getName()); } klass.setModifiers(access & ~Opcodes.ACC_SUPER); if (superName != null) { superName = AsmUtil.toQualifiedName(superName); addDep(RefType.v(superName)); klass.setSuperclass(SootResolver.v().makeClassRef(superName)); } for (String intrf : interfaces) { intrf = AsmUtil.toQualifiedName(intrf); addDep(RefType.v(intrf)); SootClass interfaceClass = SootResolver.v().makeClassRef(intrf); interfaceClass.setModifiers(interfaceClass.getModifiers() | Modifier.INTERFACE); klass.addInterface(interfaceClass); } if (signature != null) { klass.addTag(new SignatureTag(signature)); } }
/** * @apilevel internal */ private SootClass getSootClassDecl_compute() { if (erasure() != this) return erasure().getSootClassDecl(); if (compilationUnit().fromSource()) { return sootClass(); } else { if (options().verbose()) System.out.println("Loading .class file " + jvmName()); return SootResolver.v().makeClassRef(jvmName()); /* * * RefType type = (RefType) Scene.v().getRefType(jvmName()); * SootClass toReturn = null; if( type != null ) toReturn = * type.getSootClass(); if(toReturn != null) { return toReturn; } * SootClass c = new SootClass(jvmName()); c.setPhantom(true); * Scene.v().addClass(c); return c; */ // return Scene.v().getSootClass(jvmName()); /* * SootClass sc = Scene.v().loadClass(jvmName(), * SootClass.SIGNATURES); sc.setLibraryClass(); return sc; */ } }
SootResolver.v().makeClassRef(sootTypeName);