/** Returns the SootResolver currently in use. */ public SootResolver getResolver() { return SootResolver.v(); }
public SootClass forceResolve(String className, int level) { boolean tmp = doneResolving; doneResolving = false; SootClass c; try { c = SootResolver.v().resolveClass(className, level); } finally { doneResolving = tmp; } return c; }
/** * 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; }
/** * Applies a SkeletonExtractorWalker to the given SootClass, using the given Resolver to resolve the reference types it * contains. The given SootClass instance will be filled to contain a class skeleton: that is no Body instances will be * created for the class' methods. * * @param sc * a SootClass to fill in. */ public void getSkeleton(SootClass sc) { Walker w = new SkeletonExtractorWalker(SootResolver.v(), sc); mTree.apply(w); }
/** * Reads an entire class from jimple, creates the Soot objects & returns it. */ public SootClass createSootClass() { Walker w = new Walker(SootResolver.v()); mTree.apply(w); return w.getSootClass(); }
public SootClass loadClass(String className, int desiredLevel) { /* * if(Options.v().time()) Main.v().resolveTimer.start(); */ setPhantomRefs(true); // SootResolver resolver = new SootResolver(); SootResolver resolver = SootResolver.v(); SootClass toReturn = resolver.resolveClass(className, desiredLevel); setPhantomRefs(false); return toReturn; /* * if(Options.v().time()) Main.v().resolveTimer.end(); */ }
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; }
public void formAst(String fullPath, List<String> locations, String className) { Program program = SootResolver.v().getProgram(); CompilationUnit u = program.getCachedOrLoadCompilationUnit(fullPath); if (u != null && !u.isResolved) {
/** * @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; } /**
private void stashBodiesForClass(SootClass sc) { HashMap<SootMethod, JimpleBody> methodToBodyMap = new HashMap<SootMethod, JimpleBody>(); Walker w = new BodyExtractorWalker(sc, SootResolver.v(), methodToBodyMap); boolean oldPhantomValue = Scene.v().getPhantomRefs(); Scene.v().setPhantomRefs(true); mTree.apply(w); Scene.v().setPhantomRefs(oldPhantomValue); methodToParsedBodyMap = methodToBodyMap; } } // Parse
outerClassName = className.substring(0, className.lastIndexOf('$')); sc.setOuterClass(SootResolver.v().makeClassRef(outerClassName));
@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); }
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; */ } }
/** * Attempts to load the given class and all of the required support classes. Returns the original class if it was loaded, * or null otherwise. */ public SootClass tryLoadClass(String className, int desiredLevel) { /* * if(Options.v().time()) Main.v().resolveTimer.start(); */ setPhantomRefs(true); ClassSource source = SourceLocator.v().getClassSource(className); try { if (!getPhantomRefs() && source == null) { setPhantomRefs(false); return null; } } finally { if (source != null) { source.close(); } } SootResolver resolver = SootResolver.v(); SootClass toReturn = resolver.resolveClass(className, desiredLevel); setPhantomRefs(false); return toReturn; /* * if(Options.v().time()) Main.v().resolveTimer.end(); */ }