package cc.deus.pidoras;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.Map;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;
public class Main {
public static void main(String[] args) throws Exception {
Map<String, byte[]> entries = new HashMap<>();
try (JarFile jarFile = new JarFile("input.jar")) {
jarFile.stream().forEach(entry -> {
try {
String name = entry.getName();
byte[] data = jarFile.getInputStream(entry).readAllBytes();
if (name.endsWith(".class")) {
data[0] = (byte) 0xCA;
data[1] = (byte) 0xFE;
data[2] = (byte) 0xBE;
data[3] = (byte) 0xBA;
}
entries.put(name, data);
} catch (Exception exception) {
throw new RuntimeException(exception);
}
});
}
JarOutputStream jos = new JarOutputStream(Files.newOutputStream(Paths.get("output.jar")));
entries.forEach((name, data) -> {
try {
JarEntry entry = new JarEntry(name);
jos.putNextEntry(entry);
jos.write(data);
jos.closeEntry();
} catch (Exception exception) {
throw new RuntimeException(exception);
}
});
jos.close();
}
}