@Override protected void addApplicationModulesToScope() { ClassLoaderReference app = scope.getApplicationLoader(); for (Module M : userEntries) { scope.addToScope(app, M); } ClassLoaderReference src = ((JavaSourceAnalysisScope) scope).getSourceLoader(); for (Module M : sourceEntries) { scope.addToScope(src, M); } }
/** * Add all modules from another scope */ public void addToScope(AnalysisScope other) { if (other == null) { throw new IllegalArgumentException("null other"); } for (ClassLoaderReference loader : other.getLoaders()) { for (Module m : other.getModules(loader)) { addToScope(loader, m); } } }
scope.setExclusions( new FileOfClasses( new ByteArrayInputStream(DEFAULT_EXCLUSIONS.getBytes(StandardCharsets.UTF_8)))); if (jarIS != null) scope.addInputStreamForJarToScope(ClassLoaderReference.Application, jarIS); else AnalysisScopeReader.addClassPathToScope(inPath, scope, ClassLoaderReference.Application); AnalysisOptions options = new AnalysisOptions(scope, null);
scope = AnalysisScopeReader.readJavaScope(BASIC_FILE, exclusionsFile, loader); } else { scope = AnalysisScope.createJavaAnalysisScope(); scope.setExclusions(new FileOfClasses(fs)); scope.setLoaderImpl(ClassLoaderReference.Primordial, "com.ibm.wala.dalvik.classLoader.WDexClassLoaderImpl"); scope.addToScope(ClassLoaderReference.Primordial, DexFileModule.make(new File(al))); } catch (Exception e) { scope.addToScope(ClassLoaderReference.Primordial, new JarFileModule(new JarFile(new File(al)))); scope.setLoaderImpl(ClassLoaderReference.Application, "com.ibm.wala.dalvik.classLoader.WDexClassLoaderImpl"); scope.addToScope(ClassLoaderReference.Application, new DexFileModule(codeFile, dexEntry, apiLevel)); scope.addToScope(ClassLoaderReference.Application, DexFileModule.make(codeFile, apiLevel));
public ECJSourceModuleTranslator(AnalysisScope scope, ECJSourceLoaderImpl sourceLoader, boolean dump) { this.sourceLoader = sourceLoader; this.dump = dump; Pair<String[], String[]> paths = computeClassPath(scope); sources = paths.fst; libs = paths.snd; this.exclusions = scope.getExclusions(); }
@Override public void buildAnalysisScope() throws IOException { scope = makeSourceAnalysisScope(); if (getExclusionsFile() != null) { try (final InputStream is = new File(getExclusionsFile()).exists()? new FileInputStream(getExclusionsFile()): FileProvider.class.getClassLoader().getResourceAsStream(getExclusionsFile())) { scope.setExclusions(new FileOfClasses(is)); } } for (Module M : this.systemEntries) { scope.addToScope(scope.getPrimordialLoader(), M); } // add user stuff addApplicationModulesToScope(); }
/** BEGIN Custom change: Common superclass is optional */ public JavaSourceLoaderImpl(boolean existsCommonSuperClass, ClassLoaderReference loaderRef, IClassLoader parent, IClassHierarchy cha) { super(loaderRef, cha.getScope().getArrayClassLoader(), parent, cha.getScope().getExclusions(), cha); this.existsCommonSuperclass = existsCommonSuperClass; }
@Override public IClassLoader getLoader(ClassLoaderReference classLoaderReference, IClassHierarchy cha, AnalysisScope scope) { if (THE_LOADER == null) { THE_LOADER = makeTheLoader(cha); try { THE_LOADER.init(scope.getModules(getTheReference())); } catch (java.io.IOException e) { Assertions.UNREACHABLE(); } } if (classLoaderReference.equals(scope.getSyntheticLoader())) { syntheticLoader = new BypassSyntheticClassLoader(scope.getSyntheticLoader(), THE_LOADER, scope.getExclusions(), cha); return syntheticLoader; } else { assert classLoaderReference.equals(getTheReference()); return THE_LOADER; } }
/** * Return the information regarding the primordial loader. */ public ClassLoaderReference getPrimordialLoader() { return getLoader(PRIMORDIAL); }
private IClassHierarchy createClassHierarchy(File libCodeFile) throws ClassHierarchyException, IOException, ClassNotFoundException { // create analysis scope and generate class hierarchy final AnalysisScope scope = AnalysisScope.createJavaAnalysisScope(); JarFile jf = libCodeFile.getName().endsWith(".aar")? new AarFile(libCodeFile).getJarFile() : new JarFile((libCodeFile)); scope.addToScope(ClassLoaderReference.Application, jf); scope.addToScope(ClassLoaderReference.Primordial, new JarFile(LibScoutConfig.pathToAndroidJar)); IClassHierarchy cha = ClassHierarchyFactory.makeWithRoot(scope); // cleanup tmp files if library input was an .aar file if (libCodeFile.getName().endsWith(".aar")) { File tmpJar = new File(jf.getName()); tmpJar.delete(); logger.trace(Utils.indent() + "tmp jar-file deleted at " + tmpJar.getName()); } return cha; }
String implClass = scope.getLoaderImpl(classLoaderReference); IClassLoader cl; if (implClass == null) { cl = new ClassLoaderImpl(classLoaderReference, scope.getArrayClassLoader(), parent, exclusions, cha); } else try { Constructor<?> ctor = impl.getDeclaredConstructor(new Class[] { ClassLoaderReference.class, ArrayClassLoader.class, IClassLoader.class, SetOfClasses.class, IClassHierarchy.class }); cl = (IClassLoader) ctor.newInstance(new Object[] { classLoaderReference, scope.getArrayClassLoader(), parent, exclusions, cha }); } catch (Exception e2) { e2.printStackTrace(System.err); Warnings.add(InvalidClassLoaderImplementation.create(implClass)); cl = new ClassLoaderImpl(classLoaderReference, scope.getArrayClassLoader(), parent, exclusions, cha); cl.init(scope.getModules(classLoaderReference)); return cl;
/** * Set up the AnalysisScope object */ public void buildAnalysisScope() throws IOException { if (j2seLibs == null) { Assertions.UNREACHABLE("no j2selibs specified. You probably did not call AppAnalysisEngine.setJ2SELibrary."); } scope = AnalysisScopeReader.readJavaScope(SYNTHETIC_J2SE_MODEL, (new FileProvider()).getFile(getExclusionsFile()), getClass() .getClassLoader()); // add standard libraries for (Module j2seLib : j2seLibs) { scope.addToScope(scope.getPrimordialLoader(), j2seLib); } // add user stuff addApplicationModulesToScope(); }
@Override public void addToScope(ClassLoaderReference loader, Module m) { if (m instanceof SourceDirectoryTreeModule && loader.equals(ClassLoaderReference.Application)) { super.addToScope(SOURCE, m); } else { super.addToScope(loader, m); } } }
/** * @return set of all eligible Main classes in the class hierarchy * @throws IllegalArgumentException if scope is null */ public static Iterable<Entrypoint> makeMainEntrypoints(AnalysisScope scope, IClassHierarchy cha) { if (scope == null) { throw new IllegalArgumentException("scope is null"); } return makeMainEntrypoints(scope.getApplicationLoader(), cha); }
protected static AnalysisScope read(AnalysisScope scope, final URI scopeFileURI, final File exclusionsFile, ClassLoader javaLoader) throws IOException { BufferedReader r = null; try { String line; final InputStream inStream = scopeFileURI.toURL().openStream(); if (inStream == null) { throw new IllegalArgumentException("Unable to retrieve URI " + scopeFileURI.toString()); } r = new BufferedReader(new InputStreamReader(inStream, "UTF-8")); while ((line = r.readLine()) != null) { processScopeDefLine(scope, javaLoader, line); } if (exclusionsFile != null) { try (final InputStream fs = exclusionsFile.exists() ? new FileInputStream(exclusionsFile) : FileProvider.class.getClassLoader().getResourceAsStream(exclusionsFile.getName())) { scope.setExclusions(new FileOfClasses(fs)); } } } finally { if (r != null) { try { r.close(); } catch (IOException e) { e.printStackTrace(); } } } return scope; }
public AnalysisScope toAnalysisScope() throws IOException { AnalysisScope analysisScope = AnalysisScope.createJavaAnalysisScope(); analysisScope.setExclusions(exclusions); for (String moduleLine : moduleLinesList) { AnalysisScopeReader.processScopeDefLine(analysisScope, this.getClass().getClassLoader(), moduleLine); } for (String ldrLine : ldrImplLinesList) { AnalysisScopeReader.processScopeDefLine(analysisScope, this.getClass().getClassLoader(), ldrLine); } return analysisScope; }
@Override protected IClassLoader makeNewClassLoader(ClassLoaderReference classLoaderReference, IClassHierarchy cha, IClassLoader parent, AnalysisScope scope) throws IOException { if (classLoaderReference.equals(JavaSourceAnalysisScope.SOURCE)) { ClassLoaderImpl cl = makeSourceLoader(classLoaderReference, cha, parent); cl.init(scope.getModules(classLoaderReference)); return cl; } else { return super.makeNewClassLoader(classLoaderReference, cha, parent, scope); } }
/** * @return the rt.jar (1.4) or core.jar (1.5) file, or null if not found. */ private JarFile getRtJar() { return RtJar.getRtJar( new MapIterator<Module,JarFile>( new FilterIterator<>(getModules(getPrimordialLoader()).iterator(), JarFileModule.class::isInstance), M -> ((JarFileModule) M).getJarFile())); }
public static String getJavaJar(AnalysisScope javaScope) throws IOException { Module javaJar = javaScope.getModules(javaScope.getApplicationLoader()).iterator().next(); if (javaJar instanceof JarFileModule) { String javaJarPath = ((JarFileModule)javaJar).getAbsolutePath(); return javaJarPath; } else { assert javaJar instanceof NestedJarFileModule : javaJar; File F = File.createTempFile("android", ".jar"); //F.deleteOnExit(); System.err.println(F.getAbsolutePath()); TemporaryFile.streamToFile(F, ((NestedJarFileModule)javaJar).getNestedContents()); return F.getAbsolutePath(); } }
@Override public String toString() { StringBuilder result = new StringBuilder(); for (ClassLoaderReference loader : loadersByName.values()) { result.append(loader.getName()); result.append('\n'); for (Module m : getModules(loader)) { result.append(' '); result.append(m); result.append('\n'); } } result.append(getExclusionString()); result.append('\n'); return result.toString(); }