Refine search
private void addManifest(ZipOutputStream destination, Collection<File> dexFiles) throws IOException { final Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0"); manifest.getMainAttributes().put(new Attributes.Name("Created-By"), "Soot Dex Printer"); if (dexFiles != null && !dexFiles.isEmpty()) { manifest.getMainAttributes().put(new Attributes.Name("Dex-Location"), dexFiles.stream().map(File::getName).collect(Collectors.joining(" "))); } final ZipEntry manifestEntry = new ZipEntry(JarFile.MANIFEST_NAME); destination.putNextEntry(manifestEntry); manifest.write(new BufferedOutputStream(destination)); destination.closeEntry(); }
manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH.toString()); if (classpathAttribute != null) { for (String path : CLASS_PATH_ATTRIBUTE_SEPARATOR.split(classpathAttribute)) { continue; if (url.getProtocol().equals("file")) { builder.add(toFile(url));
String version = manifest.mainAttributes.getValue(versionName); if (version == null) { versionName = Attributes.Name.SIGNATURE_VERSION; version = manifest.mainAttributes.getValue(versionName); writeEntry(out, versionName, version, encoder, buffer); Iterator<?> entries = manifest.mainAttributes.keySet().iterator(); while (entries.hasNext()) { Attributes.Name name = (Attributes.Name) entries.next(); if (!name.equals(versionName)) { writeEntry(out, name, manifest.mainAttributes.getValue(name), encoder, buffer); Iterator<String> i = manifest.getEntries().keySet().iterator(); while (i.hasNext()) { String key = i.next();
File jarFile, @Nullable Manifest manifest) { if (manifest == null) { return ImmutableSet.of(); String classpathAttribute = manifest.getMainAttributes() .getValue(Attributes.Name.CLASS_PATH.toString()); if (classpathAttribute != null) { for (String path : CLASS_PATH_ATTRIBUTE_SEPARATOR.split(classpathAttribute)) { continue; if (url.getProtocol().equals("file")) { builder.add(new File(url.getFile()));
/** * Returns the class path URIs specified by the {@code Class-Path} manifest attribute, according * to <a href="http://docs.oracle.com/javase/6/docs/technotes/guides/jar/jar.html#Main%20Attributes"> * JAR File Specification</a>. If {@code manifest} is null, it means the jar file has no * manifest, and an empty set will be returned. */ @VisibleForTesting static ImmutableSet<URI> getClassPathFromManifest( File jarFile, @Nullable Manifest manifest) { if (manifest == null) { return ImmutableSet.of(); } ImmutableSet.Builder<URI> builder = ImmutableSet.builder(); String classpathAttribute = manifest.getMainAttributes() .getValue(Attributes.Name.CLASS_PATH.toString()); if (classpathAttribute != null) { for (String path : CLASS_PATH_ATTRIBUTE_SEPARATOR.split(classpathAttribute)) { URI uri; try { uri = getClassPathEntry(jarFile, path); } catch (URISyntaxException e) { // Ignore bad entry LOG.warn("Invalid Class-Path entry: " + path); continue; } builder.add(uri); } } return builder.build(); }
String getModuleVersion() { String extensionURLString = extensionURL.toString(); if (extensionURLString.contains(EXTENSION_FILE_NAME)) { String manifestUrlString = StringUtils.substringBefore(extensionURLString, EXTENSION_FILE_NAME) + "META-INF/MANIFEST.MF"; try { final Manifest manifest = new Manifest(new URL(manifestUrlString).openStream()); return manifest.getMainAttributes().getValue(new Attributes.Name("Implementation-Build")); } catch (IOException ignore) { } } return null; }
public static String getAttribute(Class<?> c, String property) throws IOException { URL codeBase = c.getProtectionDomain().getCodeSource().getLocation(); if (codeBase.getPath().endsWith(".jar")) { JarInputStream jin = null; try { jin = new JarInputStream(codeBase.openStream()); Manifest mf = jin.getManifest(); Map<Object, Object> entries = mf.getMainAttributes(); for (Iterator<Object> it = entries.keySet().iterator(); it.hasNext();) { Attributes.Name key = (Attributes.Name) it.next(); String keyName = key.toString(); if (property.equals(keyName)) { String value = (String) entries.get(key); return value; } } } finally { jin.close(); } } return null; } }
URLClassLoader cl = (URLClassLoader) Example.class.getClassLoader(); try { URL url = cl.findResource("META-INF/MANIFEST.MF"); Manifest manifest = new Manifest(url.openStream()); System.out.println(manifest.getMainAttributes().getValue(new Attributes.Name("Class-Path"))); } catch (IOException e) { // handle }
/** * obtains the MQ Light version information from the manifest. * * @return The MQ Light version. */ public static String getVersion() { String version = "unknown"; final URLClassLoader cl = (URLClassLoader)cclass.getClassLoader(); try { final URL url = cl.findResource("META-INF/MANIFEST.MF"); final Manifest manifest = new Manifest(url.openStream()); for (Entry<Object,Object> entry : manifest.getMainAttributes().entrySet()) { final Attributes.Name key = (Attributes.Name)entry.getKey(); if(Attributes.Name.IMPLEMENTATION_VERSION.equals(key)) { version = (String)entry.getValue(); } } } catch (IOException e) { logger.error("Unable to determine the product version due to error", e); } return version; } }
if (!jars.isEmpty()) { for (Path jar: jars) { classPathEntryList.add(jar.toUri().toURL().toExternalForm()); .toExternalForm(); Manifest jarManifest = new Manifest(); jarManifest.getMainAttributes().putValue( Attributes.Name.MANIFEST_VERSION.toString(), "1.0"); jarManifest.getMainAttributes().putValue( Attributes.Name.CLASS_PATH.toString(), jarClassPath);
private static File createJarFile(File jar) throws IOException, CannotCompileException, NotFoundException { Manifest manifest = new Manifest(); Attributes attrs = manifest.getMainAttributes(); attrs.put(Attributes.Name.MANIFEST_VERSION, "1.0"); attrs.put(new Attributes.Name("Premain-Class"), HotSwapAgent.class.getName()); attrs.put(new Attributes.Name("Agent-Class"), HotSwapAgent.class.getName()); attrs.put(new Attributes.Name("Can-Retransform-Classes"), "true"); attrs.put(new Attributes.Name("Can-Redefine-Classes"), "true"); JarOutputStream jos = null; try { jos = new JarOutputStream(new FileOutputStream(jar), manifest); String cname = HotSwapAgent.class.getName(); JarEntry e = new JarEntry(cname.replace('.', '/') + ".class"); jos.putNextEntry(e); ClassPool pool = ClassPool.getDefault(); CtClass clazz = pool.get(cname); jos.write(clazz.toBytecode()); jos.closeEntry(); } finally { if (jos != null) jos.close(); } return jar; } }
private Manifest convertMapToManifest(Map<String,String> attributes) { _logger.debug(LOG_ENTRY, "convertMapToManifest", new Object[]{attributes}); Manifest man = new Manifest(); Attributes att = man.getMainAttributes(); att.putValue(Attributes.Name.MANIFEST_VERSION.toString(), AppConstants.MANIFEST_VERSION); for (Map.Entry<String, String> entry : attributes.entrySet()) { att.putValue(entry.getKey(), entry.getValue()); } _logger.debug(LOG_EXIT, "convertMapToManifest", new Object[]{man}); return man; }
/** * Returns the class path URIs specified by the {@code Class-Path} manifest attribute, according * to <a href="http://docs.oracle.com/javase/6/docs/technotes/guides/jar/jar.html#Main%20Attributes"> * JAR File Specification</a>. If {@code manifest} is null, it means the jar file has no * manifest, and an empty set will be returned. */ static Set<URI> getClassPathFromManifest( File jarFile, Manifest manifest) { if (manifest == null) { return new HashSet<>(); } Set<URI> builder = new HashSet<>(); String classpathAttribute = manifest.getMainAttributes() .getValue(Attributes.Name.CLASS_PATH.toString()); if (classpathAttribute != null) { for (String path : classpathAttribute.split(" ")) { URI uri; try { uri = getClassPathEntry(jarFile, path); } catch (URISyntaxException e) { // Ignore bad entry continue; } builder.add(uri); } } return builder; }
final Manifest manifest = new Manifest(); final java.util.jar.Attributes atrs = manifest.getMainAttributes(); atrs.put(java.util.jar.Attributes.Name.MANIFEST_VERSION,"1.2"); final Map map = manifest.getEntries(); new java.util.jar.Attributes.Name("Date"); while (classes.hasMoreElements()) { final JavaClass clazz = (JavaClass)classes.nextElement(); final String className = clazz.getClassName().replace('.','/'); final java.util.jar.Attributes attr = new java.util.jar.Attributes(); attr.put(dateAttr, now); map.put(className+".class", attr);
} else if (key.equalsIgnoreCase(Attributes.Name.IMPLEMENTATION_TITLE.toString())) { foundSomething = true; dependency.addEvidence(EvidenceType.PRODUCT, source, key, value, Confidence.HIGH); addMatchingValues(classInformation, value, dependency, EvidenceType.PRODUCT); } else if (key.equalsIgnoreCase(Attributes.Name.IMPLEMENTATION_VERSION.toString())) { hasImplementationVersion = true; foundSomething = true; } else if ("specification-version".equalsIgnoreCase(key)) { specificationVersion = value; } else if (key.equalsIgnoreCase(Attributes.Name.IMPLEMENTATION_VENDOR.toString())) { foundSomething = true; dependency.addEvidence(EvidenceType.VENDOR, source, key, value, Confidence.HIGH); foundSomething = true; dependency.addEvidence(EvidenceType.VERSION, source, key, value, Confidence.HIGH); } else if (key.equalsIgnoreCase(Attributes.Name.MAIN_CLASS.toString())) { if (key.equalsIgnoreCase(Attributes.Name.IMPLEMENTATION_TITLE.toString())) { foundSomething = true; dependency.addEvidence(EvidenceType.PRODUCT, source, key, value, Confidence.MEDIUM); addMatchingValues(classInformation, value, dependency, EvidenceType.PRODUCT); } else if (key.equalsIgnoreCase(Attributes.Name.IMPLEMENTATION_VERSION.toString())) { foundSomething = true; dependency.addEvidence(EvidenceType.VERSION, source, key, value, Confidence.MEDIUM); } else if (key.equalsIgnoreCase(Attributes.Name.IMPLEMENTATION_VENDOR.toString())) { foundSomething = true; dependency.addEvidence(EvidenceType.VENDOR, source, key, value, Confidence.MEDIUM); addMatchingValues(classInformation, value, dependency, EvidenceType.VENDOR);
/** * Returns the class path (if any) from the given manifest file as an * URL list. * * @param manifest manifest file of an archive * @param rootPath root path to the module * * @return a list of URLs * an empty list if given manifest is null */ public static List<URL> getManifestClassPathAsURLs(Manifest manifest, String rootPath) { List<URL> urlList = new ArrayList<URL>(); if (manifest != null) { Attributes mainAttributes = manifest.getMainAttributes(); for (Iterator itr=mainAttributes.keySet().iterator(); itr.hasNext();) { Attributes.Name next = (Attributes.Name) itr.next(); if (next.equals(Attributes.Name.CLASS_PATH)) { String classpathString = (String) mainAttributes.get(next); urlList = getURLsFromClasspath(classpathString, " ", rootPath); } } } return urlList; }
String getManifestAttribute(String name, String defaultValue) { if (manifest == null) { return defaultValue; } Name attrName = new Name(name); Object value = manifest.getMainAttributes().get(attrName); return value == null ? defaultValue : value.toString(); }
public static void writeMainSection(OutputStream out, Attributes attributes) throws IOException { // Main section must start with the Manifest-Version attribute. // See https://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html#Signed_JAR_File. String manifestVersion = attributes.getValue(Attributes.Name.MANIFEST_VERSION); if (manifestVersion == null) { throw new IllegalArgumentException( "Mandatory " + Attributes.Name.MANIFEST_VERSION + " attribute missing"); } writeAttribute(out, Attributes.Name.MANIFEST_VERSION, manifestVersion); if (attributes.size() > 1) { SortedMap<String, String> namedAttributes = getAttributesSortedByName(attributes); namedAttributes.remove(Attributes.Name.MANIFEST_VERSION.toString()); writeAttributes(out, namedAttributes); } writeSectionDelimiter(out); }
public @Override String get(Object _k) { if (!(_k instanceof String)) { return null; } String k = (String) _k; Attributes.Name an; try { an = new Attributes.Name(k); } catch (IllegalArgumentException iae) { // Robustness, and workaround for reported MRJ locale bug: LOG.log(Level.FINE, null, iae); return null; } return attrs.getValue(an); } }