diff --git a/bombe-jar/src/main/java/org/cadixdev/bombe/jar/JarEntryTransformer.java b/bombe-jar/src/main/java/org/cadixdev/bombe/jar/JarEntryTransformer.java index 95f0865..a16bfac 100644 --- a/bombe-jar/src/main/java/org/cadixdev/bombe/jar/JarEntryTransformer.java +++ b/bombe-jar/src/main/java/org/cadixdev/bombe/jar/JarEntryTransformer.java @@ -30,6 +30,9 @@ package org.cadixdev.bombe.jar; +import java.util.Collections; +import java.util.List; + /** * A visitor for {@link AbstractJarEntry}, allowing them be be * transformed. @@ -41,9 +44,12 @@ public interface JarEntryTransformer { /** * Transforms the given class entry. + *

+ * It is possible to remove entries by returning {@code null}, when this + * occurs no further transformers will process the entry. * * @param entry The class entry - * @return The transformed entry + * @return The transformed entry, or {@code null} if the entry should be removed */ default JarClassEntry transform(final JarClassEntry entry) { return entry; @@ -51,9 +57,12 @@ default JarClassEntry transform(final JarClassEntry entry) { /** * Transforms the given resource entry. + *

+ * It is possible to remove entries by returning {@code null}, when this + * occurs no further transformers will process the entry. * * @param entry The resource entry - * @return The transformed entry + * @return The transformed entry, or {@code null} if the entry should be removed */ default JarResourceEntry transform(final JarResourceEntry entry) { return entry; @@ -61,9 +70,12 @@ default JarResourceEntry transform(final JarResourceEntry entry) { /** * Transforms the given manifest entry. + *

+ * It is possible to remove entries by returning {@code null}, when this + * occurs no further transformers will process the entry. * * @param entry The manifest entry - * @return The transformed entry + * @return The transformed entry, or {@code null} if the entry should be removed */ default JarManifestEntry transform(final JarManifestEntry entry) { return entry; @@ -71,12 +83,25 @@ default JarManifestEntry transform(final JarManifestEntry entry) { /** * Transforms the given service provider configuration entry. + *

+ * It is possible to remove entries by returning {@code null}, when this + * occurs no further transformers will process the entry. * * @param entry The service provider configuration entry - * @return The transformed entry + * @return The transformed entry, or {@code null} if the entry should be removed */ default JarServiceProviderConfigurationEntry transform(final JarServiceProviderConfigurationEntry entry) { return entry; } + /** + * Provides a list of {@link AbstractJarEntry jar entries} to add into the + * processed jar file. + * + * @return Entries to add into the final jar + */ + default List additions() { + return Collections.emptyList(); + } + } diff --git a/bombe-jar/src/main/java/org/cadixdev/bombe/jar/asm/JarEntryRemappingTransformer.java b/bombe-jar/src/main/java/org/cadixdev/bombe/jar/asm/JarEntryRemappingTransformer.java index 9252265..9b9e96a 100644 --- a/bombe-jar/src/main/java/org/cadixdev/bombe/jar/asm/JarEntryRemappingTransformer.java +++ b/bombe-jar/src/main/java/org/cadixdev/bombe/jar/asm/JarEntryRemappingTransformer.java @@ -30,9 +30,12 @@ package org.cadixdev.bombe.jar.asm; +import static java.util.jar.Attributes.Name.MAIN_CLASS; + import org.cadixdev.bombe.jar.JarClassEntry; import org.cadixdev.bombe.jar.JarEntryTransformer; import org.cadixdev.bombe.jar.JarManifestEntry; +import org.cadixdev.bombe.jar.JarResourceEntry; import org.cadixdev.bombe.jar.JarServiceProviderConfigurationEntry; import org.cadixdev.bombe.jar.ServiceProviderConfiguration; import org.objectweb.asm.ClassReader; @@ -41,7 +44,9 @@ import org.objectweb.asm.commons.ClassRemapper; import org.objectweb.asm.commons.Remapper; +import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.function.BiFunction; import java.util.jar.Attributes; import java.util.stream.Collectors; @@ -55,6 +60,8 @@ */ public class JarEntryRemappingTransformer implements JarEntryTransformer { + private static final Attributes.Name SHA_256_DIGEST = new Attributes.Name("SHA-256-Digest"); + private final Remapper remapper; private final BiFunction clsRemapper; @@ -86,14 +93,24 @@ public JarClassEntry transform(final JarClassEntry entry) { @Override public JarManifestEntry transform(final JarManifestEntry entry) { // Remap the Main-Class attribute, if present - if (entry.getManifest().getMainAttributes().containsKey(new Attributes.Name("Main-Class"))) { - final String mainClassObf = entry.getManifest().getMainAttributes().getValue("Main-Class") + if (entry.getManifest().getMainAttributes().containsKey(MAIN_CLASS)) { + final String mainClassObf = entry.getManifest().getMainAttributes().getValue(MAIN_CLASS) .replace('.', '/'); final String mainClassDeobf = this.remapper.map(mainClassObf) .replace('/', '.'); - // Since Manifest is mutable, we need'nt create a new entry \o/ - entry.getManifest().getMainAttributes().putValue("Main-Class", mainClassDeobf); + // Since Manifest is mutable, we needn't create a new entry \o/ + entry.getManifest().getMainAttributes().put(MAIN_CLASS, mainClassDeobf); + } + + // Remove all signature entries + for (final Iterator> it = entry.getManifest().getEntries().entrySet().iterator(); it.hasNext();) { + final Map.Entry section = it.next(); + if (section.getValue().remove(SHA_256_DIGEST) != null) { + if (section.getValue().isEmpty()) { + it.remove(); + } + } } return entry; @@ -119,4 +136,16 @@ public JarServiceProviderConfigurationEntry transform(final JarServiceProviderCo return new JarServiceProviderConfigurationEntry(entry.getTime(), config); } + @Override + public JarResourceEntry transform(final JarResourceEntry entry) { + // Strip signature files from metadata + if (entry.getName().startsWith("META-INF")) { + if (entry.getExtension().equals("RSA") + || entry.getExtension().equals("SF")) { + return null; + } + } + return entry; + } + } diff --git a/bombe/src/main/java/org/cadixdev/bombe/analysis/InheritanceProvider.java b/bombe/src/main/java/org/cadixdev/bombe/analysis/InheritanceProvider.java index 03bf094..7d85bb4 100644 --- a/bombe/src/main/java/org/cadixdev/bombe/analysis/InheritanceProvider.java +++ b/bombe/src/main/java/org/cadixdev/bombe/analysis/InheritanceProvider.java @@ -432,7 +432,7 @@ public Map getMethods() { @Override public Set provideParents(final InheritanceProvider provider) { if (this.parents == null) { - ClassInfo.super.provideParents(provider, this.parents = new HashSet<>()); + super.provideParents(provider, this.parents = new HashSet<>()); } return this.parents; } diff --git a/build.gradle b/build.gradle index ffa8610..952b7f6 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ subprojects { group = 'org.cadixdev' archivesBaseName = project.name.toLowerCase() - version = '0.4.3' + version = '0.4.4' repositories { mavenCentral() @@ -126,7 +126,7 @@ subprojects { developer { id = 'jamierocks' name = 'Jamie Mansfield' - email = 'dev@jamierocks.uk' + email = 'jmansfield@cadixdev.org' url = 'https://www.jamiemansfield.me/' timezone = 'Europe/London' } diff --git a/changelogs/0.3.5.md b/changelogs/0.3.5.md new file mode 100644 index 0000000..5f44066 --- /dev/null +++ b/changelogs/0.3.5.md @@ -0,0 +1,15 @@ +Bombe 0.3.5 +=== + +Bombe 0.3.5 is a small release introducing some new APIs to bolster the +capabilities of the jar transformation framework, namely allowing entries to be +introduced. To accomplish this, a `JarEntryTransformer#additions()` method has +been introduced. The `Jars` utility has been updated to support this, and a +release of Atlas will be made shortly to implement this feature. + +The `Jars` utility has been deprecated in this version, advising consumers to +switch to Atlas. Jars was removed in 0.4.0, so this just serves as a final +notice to any lingering applications using the utility. + +The remapping transformer will additionally strip signature files and entries +in the manifest. This transformer may in future be available standalone. diff --git a/changelogs/0.4.4.md b/changelogs/0.4.4.md new file mode 100644 index 0000000..b8b2284 --- /dev/null +++ b/changelogs/0.4.4.md @@ -0,0 +1,11 @@ +Bombe 0.4.4 +=== + +Bombe 0.4.4 is a small release introducing some new APIs to bolster the +capabilities of the jar transformation framework, namely allowing entries to be +introduced. To accomplish this, a `JarEntryTransformer#additions()` method has +been introduced. A release of Atlas will be made shortly to implement this +feature. + +The remapping transformer will additionally strip signature files and entries +in the manifest. This transformer may in future be available standalone.