/** * Returns the {@code Attributes} associated with the parameter entry * {@code name}. * * @param name * the name of the entry to obtain {@code Attributes} from. * @return the Attributes for the entry or {@code null} if the entry does * not exist. */ public Attributes getAttributes(String name) { return getEntries().get(name); }
/** * Returns the hash code for this instance. * * @return this {@code Manifest}'s hashCode. */ @Override public int hashCode() { return mainAttributes.hashCode() ^ getEntries().hashCode(); }
/** * Creates a new {@code Manifest} instance. The new instance will have the * same attributes as those found in the parameter {@code Manifest}. * * @param man * {@code Manifest} instance to obtain attributes from. */ @SuppressWarnings("unchecked") public Manifest(Manifest man) { mainAttributes = (Attributes) man.mainAttributes.clone(); entries = (HashMap<String, Attributes>) ((HashMap<String, Attributes>) man .getEntries()).clone(); }
/** * Determines if the receiver is equal to the parameter object. Two {@code * Manifest}s are equal if they have identical main attributes as well as * identical entry attributes. * * @param o * the object to compare against. * @return {@code true} if the manifests are equal, {@code false} otherwise */ @Override public boolean equals(Object o) { if (o == null) { return false; } if (o.getClass() != this.getClass()) { return false; } if (!mainAttributes.equals(((Manifest) o).mainAttributes)) { return false; } return getEntries().equals(((Manifest) o).getEntries()); }
/** * Return an array of <code>Extension</code> objects representing optional * packages that are available in the JAR file associated with the * specified <code>Manifest</code>. If there are no such optional * packages, a zero-length array is returned. * * @param manifest Manifest to be parsed * @return the "available" extensions in specified manifest */ public static Extension[] getAvailable(final Manifest manifest) { if (null == manifest) { return new Extension[0]; } return Stream .concat(Optional.ofNullable(manifest.getMainAttributes()) .map(Stream::of).orElse(Stream.empty()), manifest.getEntries().values().stream()) .map(attrs -> getExtension("", attrs)).filter(Objects::nonNull) .toArray(Extension[]::new); }
/** * Gets all signed files from the manifest. * <p> * It scans all manifest entries and their attributes. If there is an attribute * name which ends with "-DIGEST" we are assuming that manifest entry name is a * signed file name. * * @param manifest JAR file manifest. * @return Either empty set if none found or set of signed file names. */ private static Set<String> getSignedFiles(Manifest manifest) { Set<String> fileNames = new HashSet<>(); Map<String, Attributes> entries = manifest.getEntries(); if (entries != null && entries.size() > 0) { for (Map.Entry<String, Attributes> entry : entries.entrySet()) { Attributes attrs = entry.getValue(); for (Map.Entry<Object, Object> attrEntry : attrs.entrySet()) { if (attrEntry.getKey().toString().toUpperCase().endsWith("-DIGEST")) { fileNames.add(entry.getKey()); break; } } } } return fileNames; }
Manifest mf = new Manifest(in); mf.getMainAttributes().put(new Name("X-NOTICE"), "Modified"); mf.getEntries().clear();
int num; Map<String, Attributes> entries = manifest.getEntries(); List<String> names = new ArrayList<>(entries.keySet()); Collections.sort(names);
/** * Retrieve all the extensions listed under a particular key * (Usually EXTENSION_LIST or OPTIONAL_EXTENSION_LIST). * * @param manifest the manifest to extract extensions from * @param listKey the key used to get list (Usually * EXTENSION_LIST or OPTIONAL_EXTENSION_LIST) * @return the list of listed extensions */ private static Extension[] getListed(final Manifest manifest, final Attributes.Name listKey) { final List<Extension> results = new ArrayList<>(); final Attributes mainAttributes = manifest.getMainAttributes(); if (null != mainAttributes) { getExtension(mainAttributes, results, listKey); } manifest.getEntries().values() .forEach(attributes -> getExtension(attributes, results, listKey)); return results.toArray(new Extension[results.size()]); }
output.getEntries().put(name, attr);
/** * Return an array of <code>Package Specification</code> objects. * If there are no such optional packages, a zero-length array is returned. * * @param manifest Manifest to be parsed * @return the Package Specifications extensions in specified manifest * @throws ParseException if the attributes of the specifications cannot * be parsed according to their expected formats. */ public static Specification[] getSpecifications(final Manifest manifest) throws ParseException { if (null == manifest) { return new Specification[0]; } final List<Specification> results = new ArrayList<>(); for (Map.Entry<String, Attributes> e : manifest.getEntries().entrySet()) { Optional.ofNullable(getSpecification(e.getKey(), e.getValue())) .ifPresent(results::add); } return removeDuplicates(results) .toArray(new Specification[removeDuplicates(results).size()]); }
atrs.put(java.util.jar.Attributes.Name.MANIFEST_VERSION,"1.2"); final Map map = manifest.getEntries();
for(String key : manifest.getEntries().keySet() ) {
Iterator<String> i = manifest.getEntries().keySet().iterator(); while (i.hasNext()) { String key = i.next();
/** * A parser for {@link Manifest} bean which generates {@link ManifestModel}s * * @param name the name to assign to the generated model * @param m the manifest bean to load * @return the generated model */ private static ManifestModel parseManifest( final String name, final Manifest manifest, final AttributesFilter<Map<String, String>> filter) { final ManifestModel m = new ManifestModel(name); // Main attributes try { m.putAllEntries(filter.filter(manifest.getMainAttributes())); } catch (Exception e1) { LOGGER.log(Level.FINER, e1.getMessage(), e1); } // Map<String, Attributes> attrs = manifest.getEntries(); for (java.util.Map.Entry<String, Attributes> entry : attrs.entrySet()) { try { m.putAllEntries(filter.filter(entry.getValue())); } catch (Exception e) { LOGGER.log(Level.FINER, e.getMessage(), e); } } return m; }
Map<String, Attributes> entries = manifest.getEntries(); sf.getEntries().put(entry.getKey(), sfAttr);
for (Map.Entry<String, Attributes> item : manifest.getEntries().entrySet()) { final String name = item.getKey(); source = "manifest: " + name;
for(Map.Entry<String, Attributes> entry: man.getEntries().entrySet()) { for(Object attrkey: entry.getValue().keySet()) { if (attrkey instanceof Attributes.Name &&
for ( Map.Entry<String, Attributes> o : other.getEntries().entrySet() ) target.getEntries().put( o.getKey(), (Attributes) otherSection.clone() );
// Get Package Name String packageName = ctx.getPackageName(); // Get classes.dex file signature ApplicationInfo ai = ctx.getApplicationInfo(); String source = ai.sourceDir; JarFile jar = new JarFile(source); Manifest mf = jar.getManifest(); Map<String, Attributes> map = mf.getEntries(); Attributes a = map.get("classes.dex"); String sha1 = (String)a.getValue("SHA1-Digest");