public JarAnalyzer getJarAnalyzerByPath(String _jar_path){ if(!this.jarAnalyzerCache.containsKey(_jar_path)){ try { final JarAnalyzer ja = new JarAnalyzer(); ja.analyze(Paths.get(_jar_path).toFile()); this.jarAnalyzerCache.put(_jar_path, ja); } catch(FileAnalysisException e) { TouchPointCollector.getLog().error("Error while reading JAR file from URL [" + _jar_path + "]: " + e.getMessage()); } } return this.jarAnalyzerCache.get(_jar_path); }
/** * Called during the construction in order to have some classes frozen. * @return */ private final void freezeClasses() { try { final JavaMethodId jmi = JavaId.parseMethodQName("com.sap.Test.test()"); final ConstructUsage cu = new ConstructUsage(jmi, null, -1); final Loader l = new Loader(this.getClass().getClassLoader()); final Configuration cfg = VulasConfiguration.getGlobal().getConfiguration(); ConstructIdUtil.getInstance(); final JarWriter jw = new JarWriter(Paths.get(DynamicTransformer.class.getClassLoader().getResource(DynamicTransformer.class.getName().replace('.', '/') + ".class").toString())); final JarAnalyzer ja = new JarAnalyzer(); ja.analyze(Paths.get(DynamicTransformer.class.getClassLoader().getResource(DynamicTransformer.class.getName().replace('.', '/') + ".class").toString()).toFile()); } // Getting an exception does not matter in the context of freezing some classes catch(Exception e) {;} }
@Override public void analyze(final File _file) throws FileAnalysisException { try { super.analyze(_file);
public ArchiveFixContainmentCheck(String _b, Path _p) throws IOException, IllegalArgumentException { if(_p==null) throw new IllegalArgumentException("Filesystem path to JAR is required"); try { this.ja = new JarAnalyzer(); this.ja.analyze(_p.toFile()); ArchiveFixContainmentCheck.cp.appendClassPath(this.ja.getPath().toString()); } catch (NotFoundException e) { throw new IllegalArgumentException("JAR cannot be added to classpath: " + e.getMessage()); } catch (FileAnalysisException e) { throw new IllegalArgumentException("JAR cannot be added to classpath: " + e.getMessage()); } this.bugId = _b; } /*
private synchronized String getShaFromCachedJarAnalyzer(URL _jar_url) { // Build the JarAnalyzer (if possible) and put it into the cache if(!this.jarAnalyzersCache.containsKey(_jar_url)) { JarAnalyzer ja = null; try { final URI uri = _jar_url.toURI(); final File file = Paths.get(uri).toFile(); ja = new JarAnalyzer(); ja.analyze(file); } catch (InvalidPathException ex) { log.error("Invalid path [" + _jar_url + "]: " + ex.getMessage(), ex); } catch (FileAnalysisException ex) { log.error("Error analyzing the JAR at [" + _jar_url + "]: " + ex.getMessage(), ex); } catch(java.nio.file.FileSystemNotFoundException fsnfe) { log.error("File system not found for [" + _jar_url + "]: " + fsnfe.getMessage(), fsnfe); } catch (URISyntaxException e) { log.error("URI syntax exception for [" + _jar_url + "]: " + e.getMessage(), e); } this.jarAnalyzersCache.put(_jar_url, ja); // ja can be null } // Return the digest or null (if the JarAnalyzer could not be built) final JarAnalyzer ja = this.jarAnalyzersCache.get(_jar_url); if(ja!=null) return ja.getSHA1(); else return null; } }
try { final JarAnalyzer ja = new JarAnalyzer(); ja.analyze(Paths.get(jar_path).toFile()); this.jarFiles.put(jar_path, ja);