30
30
31
31
package org .cadixdev .bombe .asm .jar ;
32
32
33
+ import static java .util .jar .Attributes .Name .MAIN_CLASS ;
34
+
33
35
import org .cadixdev .bombe .jar .JarClassEntry ;
34
36
import org .cadixdev .bombe .jar .JarEntryTransformer ;
35
37
import org .cadixdev .bombe .jar .JarManifestEntry ;
38
+ import org .cadixdev .bombe .jar .JarResourceEntry ;
36
39
import org .cadixdev .bombe .jar .JarServiceProviderConfigurationEntry ;
37
40
import org .cadixdev .bombe .jar .ServiceProviderConfiguration ;
38
41
import org .objectweb .asm .ClassReader ;
41
44
import org .objectweb .asm .commons .ClassRemapper ;
42
45
import org .objectweb .asm .commons .Remapper ;
43
46
47
+ import java .util .Iterator ;
44
48
import java .util .List ;
49
+ import java .util .Map ;
45
50
import java .util .function .BiFunction ;
46
51
import java .util .jar .Attributes ;
47
52
import java .util .stream .Collectors ;
55
60
*/
56
61
public class JarEntryRemappingTransformer implements JarEntryTransformer {
57
62
63
+ private static final Attributes .Name SHA_256_DIGEST = new Attributes .Name ("SHA-256-Digest" );
64
+
58
65
private final Remapper remapper ;
59
66
private final BiFunction <ClassVisitor , Remapper , ClassRemapper > clsRemapper ;
60
67
@@ -86,14 +93,24 @@ public JarClassEntry transform(final JarClassEntry entry) {
86
93
@ Override
87
94
public JarManifestEntry transform (final JarManifestEntry entry ) {
88
95
// Remap the Main-Class attribute, if present
89
- if (entry .getManifest ().getMainAttributes ().containsKey (new Attributes . Name ( "Main-Class" ) )) {
90
- final String mainClassObf = entry .getManifest ().getMainAttributes ().getValue ("Main-Class" )
96
+ if (entry .getManifest ().getMainAttributes ().containsKey (MAIN_CLASS )) {
97
+ final String mainClassObf = entry .getManifest ().getMainAttributes ().getValue (MAIN_CLASS )
91
98
.replace ('.' , '/' );
92
99
final String mainClassDeobf = this .remapper .map (mainClassObf )
93
100
.replace ('/' , '.' );
94
101
95
- // Since Manifest is mutable, we need'nt create a new entry \o/
96
- entry .getManifest ().getMainAttributes ().putValue ("Main-Class" , mainClassDeobf );
102
+ // Since Manifest is mutable, we needn't create a new entry \o/
103
+ entry .getManifest ().getMainAttributes ().put (MAIN_CLASS , mainClassDeobf );
104
+ }
105
+
106
+ // Remove all signature entries
107
+ for (final Iterator <Map .Entry <String , Attributes >> it = entry .getManifest ().getEntries ().entrySet ().iterator (); it .hasNext ();) {
108
+ final Map .Entry <String , Attributes > section = it .next ();
109
+ if (section .getValue ().remove (SHA_256_DIGEST ) != null ) {
110
+ if (section .getValue ().isEmpty ()) {
111
+ it .remove ();
112
+ }
113
+ }
97
114
}
98
115
99
116
return entry ;
@@ -119,4 +136,15 @@ public JarServiceProviderConfigurationEntry transform(final JarServiceProviderCo
119
136
return new JarServiceProviderConfigurationEntry (entry .getTime (), config );
120
137
}
121
138
139
+ @ Override
140
+ public JarResourceEntry transform (final JarResourceEntry entry ) {
141
+ // Strip signature files from metadata
142
+ if (entry .getName ().startsWith ("META-INF" )) {
143
+ if (entry .getExtension ().equals ("RSA" )
144
+ || entry .getExtension ().equals ("SF" )) {
145
+ return null ;
146
+ }
147
+ }
148
+ return entry ;
149
+ }
122
150
}
0 commit comments