public static String getVersion() { try { ClassLoader classLoader = Jadx.class.getClassLoader(); if (classLoader != null) { Enumeration<URL> resources = classLoader.getResources("META-INF/MANIFEST.MF"); while (resources.hasMoreElements()) { Manifest manifest = new Manifest(resources.nextElement().openStream()); String ver = manifest.getMainAttributes().getValue("jadx-version"); if (ver != null) { return ver; } } } } catch (Exception e) { LOG.error("Can't get manifest file", e); } return "dev"; } }
/** * {@inheritDoc} */ public File toJar(File file) throws IOException { Manifest manifest = new Manifest(); manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, MANIFEST_VERSION); return toJar(file, manifest); }
Manifest input = jar.getManifest(); Manifest output = new Manifest(); Attributes main = output.getMainAttributes(); if (input != null) { main.putAll(input.getMainAttributes()); main.putValue("Manifest-Version", "1.0"); main.putValue("Created-By", "1.6.0_21 (d2j-" + AbstractJarSign.class.getPackage().getImplementationVersion() + ")"); for (Enumeration<JarEntry> e = jar.entries(); e.hasMoreElements();) { JarEntry entry = e.nextElement(); byName.put(entry.getName(), entry); String name = entry.getName(); if (!entry.isDirectory() && !name.equals(JarFile.MANIFEST_NAME) && !stripPattern.matcher(name).matches()) { InputStream data = jar.getInputStream(entry); while ((num = data.read(buffer)) > 0) { md.update(buffer, 0, num); attr = input.getAttributes(name); attr = attr != null ? new Attributes(attr) : new Attributes(); attr.putValue(digName, encodeBase64(md.digest())); output.getEntries().put(name, attr);
public void addManifestV0(final String embulkPluginMainClass) { final Attributes attributes = this.manifest.getMainAttributes(); attributes.put(Attributes.Name.MANIFEST_VERSION, "1.0"); attributes.putValue(MANIFEST_PLUGIN_SPI_VERSION, "0"); attributes.putValue(MANIFEST_PLUGIN_MAIN_CLASS, embulkPluginMainClass); }
Class clazz = MyClass.class; String className = clazz.getSimpleName() + ".class"; String classPath = clazz.getResource(className).toString(); if (!classPath.startsWith("jar")) { // Class not from JAR return; } String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF"; Manifest manifest = new Manifest(new URL(manifestPath).openStream()); Attributes attr = manifest.getMainAttributes(); String value = attr.getValue("Manifest-Version");
JarFile jarFile = null; try { jarFile = new JarFile(pathComponent); Manifest manifest = jarFile.getManifest(); if (manifest == null) { return; classpath = manifest.getMainAttributes() .getValue(Attributes.Name.CLASS_PATH); } finally { if (jarFile != null) { jarFile.close(); while (st.hasMoreTokens()) { String classpathElement = st.nextToken(); URL libraryURL = new URL(baseURL, classpathElement); if (!libraryURL.getProtocol().equals("file")) { log("Skipping jar library " + classpathElement + " since only relative URLs are supported by this" + " loader", continue; String decodedPath = Locator.decodeUri(libraryURL.getFile()); File libraryFile = new File(decodedPath); if (libraryFile.exists() && !isInPath(libraryFile)) {
try { try { Manifest manifest = new Manifest(inputStream); Map<Attributes.Name, String> values = new HashMap<Attributes.Name, String>(); Attributes mainAttributes = manifest.getMainAttributes(); if (mainAttributes != null) { for (Attributes.Name attributeName : ATTRIBUTE_NAMES) { values.put(attributeName, mainAttributes.getValue(attributeName)); Attributes attributes = manifest.getAttributes(packageName.replace('.', '/').concat("/")); if (attributes != null) { for (Attributes.Name attributeName : ATTRIBUTE_NAMES) { String value = attributes.getValue(attributeName); if (value != null) { values.put(attributeName, value); : NOT_SEALED); } finally { inputStream.close();
protected String identifyPluginShortName(File t) { try { JarFile j = new JarFile(t); try { String name = j.getManifest().getMainAttributes().getValue("Short-Name"); if (name!=null) return name; } finally { j.close(); } } catch (IOException e) { LOGGER.log(WARNING, "Failed to identify the short name from "+t,e); } return FilenameUtils.getBaseName(t.getName()); // fall back to the base name of what's uploaded }
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));
private static boolean isPluginManifest(Manifest mf) { Attributes attr = mf.getMainAttributes(); return attr.getValue("Short-Name") != null && (attr.getValue("Plugin-Version") != null || attr.getValue("Jenkins-Version") != null) || "true".equals(attr.getValue("Jenkins-ClassFilter-Whitelisted")); }
private boolean isOsgi( Jar jar ) throws Exception { if ( jar.getManifest() != null ) { return jar.getManifest().getMainAttributes().getValue( Analyzer.BUNDLE_NAME ) != null; } return false; }
String specificationVersion = null; boolean hasImplementationVersion = false; Attributes atts = manifest.getMainAttributes(); for (Entry<Object, Object> entry : atts.entrySet()) { String key = entry.getKey().toString(); String value = atts.getValue(key); if (HTML_DETECTION_PATTERN.matcher(value).find()) { value = Jsoup.parse(value).text(); } 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); for (Map.Entry<String, Attributes> item : manifest.getEntries().entrySet()) { final String name = item.getKey(); source = "manifest: " + name; atts = item.getValue(); for (Entry<Object, Object> entry : atts.entrySet()) { final String key = entry.getKey().toString(); final String value = atts.getValue(key);
if (sourceManifestBytes != null) { try { sourceManifest = new Manifest(new ByteArrayInputStream(sourceManifestBytes)); } catch (IOException e) { throw new IllegalArgumentException("Failed to parse source MANIFEST.MF", e); Attributes mainAttrs = new Attributes(); mainAttrs.putAll(sourceManifest.getMainAttributes()); } else { mainAttrs.put(Attributes.Name.MANIFEST_VERSION, ATTRIBUTE_VALUE_MANIFEST_VERSION); mainAttrs.put(ATTRIBUTE_NAME_CREATED_BY, ATTRIBUTE_DEFALT_VALUE_CREATED_BY); for (String entryName : sortedEntryNames) { byte[] entryDigest = jarEntryDigests.get(entryName); Attributes entryAttrs = new Attributes(); entryAttrs.putValue( entryDigestAttributeName, Base64.getEncoder().encodeToString(entryDigest));
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(); }
private static String defaultMainClassName(JarFile jarFile) throws IOException { return jarFile.getManifest().getMainAttributes().getValue("GoCD-Main-Class"); } }
private static String getManifestKey(JarFile jarFile, String key) { try { Manifest manifest = jarFile.getManifest(); if (manifest != null) { Attributes attributes = manifest.getMainAttributes(); return attributes.getValue(key); } } catch (IOException e) { LOG.error("Exception while trying to read key {} from manifest of {}", key, jarFile.getName(), e); } return null; }
Manifest sf = new Manifest(); Attributes main = sf.getMainAttributes(); main.putValue("Signature-Version", "1.0"); main.putValue("Created-By", "1.6.0_21 (d2j-" + AbstractJarSign.class.getPackage().getImplementationVersion() + ")"); manifest.write(print); print.flush(); main.putValue(digestAlg + "-Digest-Manifest", encodeBase64(md.digest())); Manifest m2 = new Manifest(); m2.getMainAttributes().putAll(manifest.getMainAttributes()); m2.write(print); main.putValue(digestAlg + "-Digest-Manifest-Main-Attributes", encodeBase64(md.digest())); print.write(entry.getKey().getBytes(StandardCharsets.UTF_8)); print.write(EOL); for (Map.Entry<Object, Object> att : entry.getValue().entrySet()) { print.write(att.getKey().toString().getBytes(StandardCharsets.UTF_8)); print.write(COL); print.flush(); Attributes sfAttr = new Attributes(); sfAttr.putValue(digName, encodeBase64(md.digest())); sf.getEntries().put(entry.getKey(), sfAttr);
@Test public void singleManifest() throws Exception { Manifest mf = new Manifest(); mf.getMainAttributes().putValue("foo", "bar"); mf.getMainAttributes().putValue("other", "value"); File jar = createJar(mf, "singleManifest.jar"); URLClassLoader classloader = new URLClassLoader(FileUtils.toURLs(new File[]{jar})); List<String> values = ManifestUtils.getPropertyValues(classloader, "foo"); assertThat(values).containsOnly("bar"); }
public Map<String, String> getManifest(final InputStream input) { final Map<String, String> retMap = new HashMap<String, String>(); try { Manifest manifest = new Manifest(); manifest.read(input); final Attributes attributes = manifest.getMainAttributes(); for (final Map.Entry attribute : attributes.entrySet()) { retMap.put(attribute.getKey().toString(), attribute.getValue().toString()); } } catch (final Exception ex) { logger.error( "Failed to load manifest ", ex); } return retMap; }
public String getVersion() throws Exception { check(); Manifest m = getManifest(); if (m == null) return null; String s = m.getMainAttributes().getValue(Constants.BUNDLE_VERSION); if (s == null) return null; return s.trim(); }