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"; } }
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 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);
/** * {@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); }
private boolean isSealed(Manifest manifest, String dirName) { Attributes attributes = manifest.getAttributes(dirName); if (attributes != null) { String value = attributes.getValue(Attributes.Name.SEALED); if (value != null) { return value.equalsIgnoreCase("true"); } } Attributes mainAttributes = manifest.getMainAttributes(); String value = mainAttributes.getValue(Attributes.Name.SEALED); return (value != null && value.equalsIgnoreCase("true")); }
private static Manifest loadManifest(String jarUrl) throws Exception { InputStream is = new URL(jarUrl + "!/META-INF/MANIFEST.MF").openStream(); try { return new Manifest(is); } finally { is.close(); } }
JarFile jar = new JarFile(new File("path/to/your/jar-file")); InputStream is = jar.getInputStream(jar.getEntry("META-INF/MANIFEST.MF")); Manifest man = new Manifest(is); is.close(); for(Map.Entry<String, Attributes> entry: man.getEntries().entrySet()) { for(Object attrkey: entry.getValue().keySet()) { if (attrkey instanceof Attributes.Name && ((Attributes.Name)attrkey).toString().indexOf("-Digest") != -1) signed.add(entry.getKey()); for(Enumeration<JarEntry> entry = jar.entries(); entry.hasMoreElements(); ) { JarEntry je = entry.nextElement(); if (!je.isDirectory()) entries.add(je.getName());
Enumeration<URL> resources = getClass().getClassLoader() .getResources("META-INF/MANIFEST.MF"); while (resources.hasMoreElements()) { try { Manifest manifest = new Manifest(resources.nextElement().openStream()); // check that this is your manifest and do what you need or get the next one ... } catch (IOException E) { // handle } }
/** * {@inheritDoc} */ public Manifest getManifest() throws IOException { File file = new File(folder, JarFile.MANIFEST_NAME); if (file.exists()) { InputStream inputStream = new FileInputStream(file); try { return new Manifest(inputStream); } finally { inputStream.close(); } } else { return NO_MANIFEST; } }
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();
URL sealBase = null; Attributes sectionAttributes = manifest.getAttributes(sectionName); if (sectionAttributes != null) { specificationTitle = sectionAttributes.getValue(Name.SPECIFICATION_TITLE); specificationVendor = sectionAttributes.getValue(Name.SPECIFICATION_VENDOR); specificationVersion = sectionAttributes.getValue(Name.SPECIFICATION_VERSION); implementationTitle = sectionAttributes.getValue(Name.IMPLEMENTATION_TITLE); implementationVendor = sectionAttributes.getValue(Name.IMPLEMENTATION_VENDOR); sealedString = sectionAttributes.getValue(Name.SEALED); Attributes mainAttributes = manifest.getMainAttributes(); if (mainAttributes != null) { if (specificationTitle == null) { sealBase = new URL(FileUtils.getFileUtils().toURI(container.getAbsolutePath())); } catch (MalformedURLException e) {
int num; Map<String, Attributes> entries = manifest.getEntries(); List<String> names = new ArrayList<>(entries.keySet()); Collections.sort(names); for (String name : names) { JarEntry inEntry = in.getJarEntry(name); JarEntry outEntry = null; if (inEntry.getMethod() == JarEntry.STORED) { out.putNextEntry(outEntry); InputStream data = in.getInputStream(inEntry); while ((num = data.read(buffer)) > 0) { out.write(buffer, 0, num);
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 }
public Manifest getManifest() throws Exception { check(); if (manifest == null) { Resource manifestResource = getResource("META-INF/MANIFEST.MF"); if (manifestResource != null) { InputStream in = manifestResource.openInputStream(); manifest = new Manifest(in); in.close(); } } return manifest; }
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));
URLClassLoader cl = (URLClassLoader) getClass().getClassLoader(); try { URL url = cl.findResource("META-INF/MANIFEST.MF"); Manifest manifest = new Manifest(url.openStream()); // do stuff with it ... } catch (IOException E) { // handle }
/*package*/ static @CheckForNull Manifest parsePluginManifest(URL bundledJpi) { try { URLClassLoader cl = new URLClassLoader(new URL[]{bundledJpi}); InputStream in=null; try { URL res = cl.findResource(PluginWrapper.MANIFEST_FILENAME); if (res!=null) { in = getBundledJpiManifestStream(res); Manifest manifest = new Manifest(in); return manifest; } } finally { Util.closeAndLogFailures(in, LOGGER, PluginWrapper.MANIFEST_FILENAME, bundledJpi.toString()); if (cl instanceof Closeable) ((Closeable)cl).close(); } } catch (IOException e) { LOGGER.log(WARNING, "Failed to parse manifest of "+bundledJpi, e); } return null; }
private String getVersionOf(Manifest manifest) { String v = manifest.getMainAttributes().getValue("Plugin-Version"); if(v!=null) return v; // plugins generated before maven-hpi-plugin 1.3 should still have this attribute v = manifest.getMainAttributes().getValue("Implementation-Version"); if(v!=null) return v; return "???"; }
private boolean isOsgi( Jar jar ) throws Exception { if ( jar.getManifest() != null ) { return jar.getManifest().getMainAttributes().getValue( Analyzer.BUNDLE_NAME ) != null; } return false; }
private static String defaultMainClassName(JarFile jarFile) throws IOException { return jarFile.getManifest().getMainAttributes().getValue("GoCD-Main-Class"); } }