Skip to content
This repository has been archived by the owner on Oct 29, 2023. It is now read-only.

Commit

Permalink
Save classes to file in a random order
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderhenne committed Oct 13, 2017
1 parent 078d27f commit f8feb26
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/main/java/com/uniquepassive/mystery/util/JarUtil.java
Expand Up @@ -9,8 +9,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collection;
import java.util.Map;
import java.util.*;
import java.util.function.Function;
import java.util.jar.JarFile;
import java.util.stream.Collectors;
Expand All @@ -24,7 +23,8 @@ public static Map<String, ClassNode> parseJar(File targetJar)

JarFile jarFile = new JarFile(targetJar);

return jarFile.stream()
return jarFile
.stream()
.filter(e -> e.getName().toLowerCase().endsWith(".class"))
.map(e -> {
try (InputStream classStream = jarFile.getInputStream(e)) {
Expand All @@ -42,8 +42,18 @@ public static Map<String, ClassNode> parseJar(File targetJar)
public static void saveToFile(File targetJar, Collection<ClassNode> classes)
throws IOException {

List<ClassNode> classList = new ArrayList<>(classes);

/*
Shuffle the class list
so that the file order
in the output jar isn't
the same as the input order.
*/
Collections.shuffle(classList);

try (ZipOutputStream zipFile = new ZipOutputStream(new FileOutputStream(targetJar))) {
classes.forEach((c) -> {
classList.forEach((c) -> {
try {
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS);
c.accept(classWriter);
Expand Down

0 comments on commit f8feb26

Please sign in to comment.