Skip to content

Instantly share code, notes, and snippets.

@Runemoro
Created July 18, 2019 04:01
Show Gist options
  • Save Runemoro/763f8f2bf85f688a790df4cf1b554d9c to your computer and use it in GitHub Desktop.
Save Runemoro/763f8f2bf85f688a790df4cf1b554d9c to your computer and use it in GitHub Desktop.
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