Created
July 18, 2019 04:01
-
-
Save Runemoro/763f8f2bf85f688a790df4cf1b554d9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.objectweb.asm.*; | |
import java.io.FileOutputStream; | |
import java.util.Collections; | |
import java.util.jar.JarEntry; | |
import java.util.jar.JarFile; | |
import java.util.jar.JarOutputStream; | |
public class AnnotationRemover { | |
private static final String INPUT = "remapped.jar"; | |
private static final String OUTPUT = "remapped-no-annotations.jar"; | |
public static void main(String[] args) throws Exception { | |
try (JarFile fromJar = new JarFile(INPUT); | |
JarOutputStream outputJar = new JarOutputStream(new FileOutputStream(OUTPUT))) { | |
for (JarEntry entry : Collections.list(fromJar.entries())) { | |
if (!entry.getName().endsWith(".class")) { | |
continue; | |
} | |
ClassWriter classWriter = new ClassWriter(0); | |
new ClassReader(fromJar.getInputStream(entry)).accept(new ClassVisitor(Opcodes.ASM7, classWriter) { | |
@Override | |
public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) { | |
return descriptor.startsWith("Lnet/fabricmc") ? null : super.visitAnnotation(descriptor, visible); | |
} | |
}, 0); | |
outputJar.putNextEntry(new JarEntry(entry.getName())); | |
outputJar.write(classWriter.toByteArray()); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment