@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); } } }
@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); } } }
@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); } }
public AnalysisScope toAnalysisScope(AnalysisScope scope) { for (Map.Entry<ILoader, List<Module>> entry : modules.entrySet()) { for (Module m : entry.getValue()) { scope.addToScope(entry.getKey().ref(), m); } } return scope; }
@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); } }
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; }
/** * 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); } } }
/** * Add the application modules to the analysis scope. */ protected void addApplicationModulesToScope() { ClassLoaderReference app = scope.getApplicationLoader(); for (Object o : moduleFiles) { if (!(o instanceof Module)) { Assertions.UNREACHABLE("Unexpected type: " + o.getClass()); } Module M = (Module) o; scope.addToScope(app, 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); } } }
/** * Add the application modules to the analysis scope. */ protected void addApplicationModulesToScope() { ClassLoaderReference app = scope.getApplicationLoader(); for (Object o : moduleFiles) { if (!(o instanceof Module)) { Assertions.UNREACHABLE("Unexpected type: " + o.getClass()); } Module M = (Module) o; scope.addToScope(app, M); } }
/** END Custom change: Fixes in AndroidAnalysisScope */ public static AnalysisScope makeAndroidBinaryAnalysisScope( URI classPath, String exclusionsFile) throws IOException { if (classPath == null) { throw new IllegalArgumentException("classPath null"); } AnalysisScope scope = AnalysisScopeReader.readJavaScope(BASIC_FILE, new File(exclusionsFile), WALA_CLASSLOADER); ClassLoaderReference loader = scope.getLoader(AnalysisScope.APPLICATION); final String path = classPath.getPath(); if (path.endsWith(".jar") || path.endsWith(".apk") || path.endsWith(".dex")) { scope.addToScope(loader, DexFileModule.make(new File(classPath))); } else { throw new IOException( "could not determine type of classpath from file extension: " + path); } return scope; } }
/** * Enhance an {@link AnalysisScope} to include in a particular loader, elements from a set of Eclipse projects * * @param loader the class loader in which new {@link Module}s will live * @param projectPaths Eclipse project paths to add to the analysis scope * @param scope the {@link AnalysisScope} under construction. This will be mutated. * @param seen set of {@link Module}s which have already been seen, and should not be added to the analysis scope */ private static void buildScope(ClassLoaderReference loader, Collection<EclipseProjectPath<?, ?>> projectPaths, AnalysisScope scope, Collection<Module> seen) throws IOException { for (EclipseProjectPath<?, ?> path : projectPaths) { AnalysisScope pScope = path.toAnalysisScope((File) null); for (Module m : pScope.getModules(loader)) { if (!seen.contains(m)) { seen.add(m); scope.addToScope(loader, m); } } } }
/** END Custom change: Fixes in AndroidAnalysisScope */ public static AnalysisScope makeAndroidBinaryAnalysisScope( URI classPath, String exclusionsFile) throws IOException { if (classPath == null) { throw new IllegalArgumentException("classPath null"); } AnalysisScope scope = AnalysisScopeReader.readJavaScope(BASIC_FILE, new File(exclusionsFile), WALA_CLASSLOADER); ClassLoaderReference loader = scope.getLoader(AnalysisScope.APPLICATION); final String path = classPath.getPath(); if (path.endsWith(".jar") || path.endsWith(".apk") || path.endsWith(".dex")) { scope.addToScope(loader, DexFileModule.make(new File(classPath))); } else { throw new IOException( "could not determine type of classpath from file extension: " + path); } return scope; } }
@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(); }
@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(); }
/** * 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(); }
/** * 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(); }
public static AnalysisScope makeDalvikScope(URI[] androidLibs, File androidAPIJar, String dexFileName) throws IOException { if (androidLibs != null) { return AndroidAnalysisScope.setUpAndroidAnalysisScope( new File(dexFileName).toURI(), CallGraphTestUtil.REGRESSION_EXCLUSIONS, CallGraphTestUtil.class.getClassLoader(), androidLibs); } else { AnalysisScope scope = AndroidAnalysisScope.setUpAndroidAnalysisScope( new File(dexFileName).toURI(), CallGraphTestUtil.REGRESSION_EXCLUSIONS, CallGraphTestUtil.class.getClassLoader()); if (androidAPIJar != null) { scope.addToScope(ClassLoaderReference.Primordial, new JarFileModule(new JarFile(androidAPIJar))); } return scope; } }
private static void addAPKtoScope(ClassLoaderReference loader, AnalysisScope scope, String fileName){ File apkFile = new File(fileName); MultiDexContainer<? extends DexBackedDexFile> multiDex = null; try { multiDex = DexFileFactory.loadDexContainer(apkFile, Opcodes.forApi(24)); } catch (IOException e) { throw new RuntimeException(e); } try{ for (String dexEntry : multiDex.getDexEntryNames()) { System.out.println("Adding dex file: " +dexEntry + " of file:" + fileName); scope.addToScope(loader, new DexFileModule(apkFile, dexEntry,24)); } }catch (IOException e){ throw new RuntimeException(e); } }
private void testOCamlJar(String jarFile, String... args) throws ClassHierarchyException, IllegalArgumentException, CancelException, IOException, ClassNotFoundException, InvalidClassFileException, FailureException, SecurityException, InterruptedException { File F = TemporaryFile.urlToFile(jarFile.replace('.', '_') + ".jar", getClass().getClassLoader().getResource(jarFile)); F.deleteOnExit(); AnalysisScope scope = CallGraphTestUtil.makeJ2SEAnalysisScope("base.txt", CallGraphTestUtil.REGRESSION_EXCLUSIONS); scope.addToScope(ClassLoaderReference.Application, new JarFile(F, false)); ClassHierarchy cha = ClassHierarchyFactory.make(scope); Iterable<Entrypoint> entrypoints = com.ibm.wala.ipa.callgraph.impl.Util.makeMainEntrypoints(scope, cha, "Lpack/ocamljavaMain"); AnalysisOptions options = CallGraphTestUtil.makeAnalysisOptions(scope, entrypoints); options.setUseConstantSpecificKeys(true); IAnalysisCacheView cache = new AnalysisCacheImpl(); SSAPropagationCallGraphBuilder builder = Util.makeZeroCFABuilder(Language.JAVA, options, cache, cha, scope); MethodHandles.analyzeMethodHandles(options, builder); CallGraph cg = builder.makeCallGraph(options, null); System.err.println(cg); instrument(F.getAbsolutePath()); run("pack.ocamljavaMain", null, args); checkNodes(cg, t -> { String s = t.toString(); return s.contains("Lpack/") || s.contains("Locaml/stdlib/"); }); }