From 96e552d096b7249c22973d2bdb0d457b047056e8 Mon Sep 17 00:00:00 2001 From: Col-E Date: Sun, 20 Feb 2022 20:49:07 -0500 Subject: [PATCH] Reorganize sample directory structure --- .../coley/cafedude/CrasherPatchingTest.java | 2 +- .../me/coley/cafedude/EqualityIOTest.java | 65 ++++++++---------- .../samples/{ => normal}/annos/Anno.class | Bin .../samples/{ => normal}/annos/Anno.java | 0 .../normal/annos/CommandLine$Command.class | Bin 0 -> 3535 bytes .../samples/{ => normal}/annos/Sample.class | Bin .../samples/{ => normal}/annos/Sample.java | 0 .../samples/{ => normal}/javac/Conf.class | Bin .../{ => normal}/javac/ConfDisplay.class | Bin .../javac/InstrumentationResource$1.class | Bin ...e$InstrumentationResourceTransformer.class | Bin .../javac/InstrumentationResource.class | Bin .../samples/{ => normal}/javac/Vector.class | Bin .../{ => normal}/javac/Workspace.class | Bin .../{ => normal}/javac/WorkspaceIO$1.class | Bin .../{ => normal}/javac/WorkspaceIO.class | Bin .../misc/FileAlterationMonitor.class | Bin .../samples/{ => normal}/misc/IndyTest.class | Bin .../modules/module-info-javafx-controls.class | Bin .../{ => obfuscated}/crasher/sample1.class | Bin .../{ => obfuscated}/crasher/sample10.class | Bin .../{ => obfuscated}/crasher/sample11.class | Bin .../{ => obfuscated}/crasher/sample12.class | Bin .../{ => obfuscated}/crasher/sample13.class | Bin .../{ => obfuscated}/crasher/sample14.class | Bin .../{ => obfuscated}/crasher/sample15.class | Bin .../crasher/sample16.class} | Bin .../crasher/sample17.class} | Bin .../crasher/sample18.class} | Bin .../crasher/sample19.class} | Bin .../{ => obfuscated}/crasher/sample2.class | Bin .../crasher/sample20.class} | Bin .../{ => obfuscated}/crasher/sample21.class | Bin .../{ => obfuscated}/crasher/sample22.class | Bin .../{ => obfuscated}/crasher/sample23.class | Bin .../{ => obfuscated}/crasher/sample24.class | Bin .../{ => obfuscated}/crasher/sample25.class | Bin .../{ => obfuscated}/crasher/sample26.class | Bin .../{ => obfuscated}/crasher/sample27.class | Bin .../{ => obfuscated}/crasher/sample28.class | Bin .../{ => obfuscated}/crasher/sample29.class | Bin .../{ => obfuscated}/crasher/sample3.class | Bin .../{ => obfuscated}/crasher/sample4.class | Bin .../{ => obfuscated}/crasher/sample5.class | Bin .../{ => obfuscated}/crasher/sample6.class | Bin .../{ => obfuscated}/crasher/sample7.class | Bin .../{ => obfuscated}/crasher/sample8.class | Bin .../{ => obfuscated}/crasher/sample9.class | Bin 48 files changed, 30 insertions(+), 37 deletions(-) rename src/test/resources/samples/{ => normal}/annos/Anno.class (100%) rename src/test/resources/samples/{ => normal}/annos/Anno.java (100%) create mode 100644 src/test/resources/samples/normal/annos/CommandLine$Command.class rename src/test/resources/samples/{ => normal}/annos/Sample.class (100%) rename src/test/resources/samples/{ => normal}/annos/Sample.java (100%) rename src/test/resources/samples/{ => normal}/javac/Conf.class (100%) rename src/test/resources/samples/{ => normal}/javac/ConfDisplay.class (100%) rename src/test/resources/samples/{ => normal}/javac/InstrumentationResource$1.class (100%) rename src/test/resources/samples/{ => normal}/javac/InstrumentationResource$InstrumentationResourceTransformer.class (100%) rename src/test/resources/samples/{ => normal}/javac/InstrumentationResource.class (100%) rename src/test/resources/samples/{ => normal}/javac/Vector.class (100%) rename src/test/resources/samples/{ => normal}/javac/Workspace.class (100%) rename src/test/resources/samples/{ => normal}/javac/WorkspaceIO$1.class (100%) rename src/test/resources/samples/{ => normal}/javac/WorkspaceIO.class (100%) rename src/test/resources/samples/{ => normal}/misc/FileAlterationMonitor.class (100%) rename src/test/resources/samples/{ => normal}/misc/IndyTest.class (100%) rename src/test/resources/samples/{ => normal}/modules/module-info-javafx-controls.class (100%) rename src/test/resources/samples/{ => obfuscated}/crasher/sample1.class (100%) rename src/test/resources/samples/{ => obfuscated}/crasher/sample10.class (100%) rename src/test/resources/samples/{ => obfuscated}/crasher/sample11.class (100%) rename src/test/resources/samples/{ => obfuscated}/crasher/sample12.class (100%) rename src/test/resources/samples/{ => obfuscated}/crasher/sample13.class (100%) rename src/test/resources/samples/{ => obfuscated}/crasher/sample14.class (100%) rename src/test/resources/samples/{ => obfuscated}/crasher/sample15.class (100%) rename src/test/resources/samples/{crasher/Sample16.class => obfuscated/crasher/sample16.class} (100%) rename src/test/resources/samples/{crasher/Sample17.class => obfuscated/crasher/sample17.class} (100%) rename src/test/resources/samples/{crasher/Sample18.class => obfuscated/crasher/sample18.class} (100%) rename src/test/resources/samples/{crasher/Sample19.class => obfuscated/crasher/sample19.class} (100%) rename src/test/resources/samples/{ => obfuscated}/crasher/sample2.class (100%) rename src/test/resources/samples/{crasher/Sample20.class => obfuscated/crasher/sample20.class} (100%) rename src/test/resources/samples/{ => obfuscated}/crasher/sample21.class (100%) rename src/test/resources/samples/{ => obfuscated}/crasher/sample22.class (100%) rename src/test/resources/samples/{ => obfuscated}/crasher/sample23.class (100%) rename src/test/resources/samples/{ => obfuscated}/crasher/sample24.class (100%) rename src/test/resources/samples/{ => obfuscated}/crasher/sample25.class (100%) rename src/test/resources/samples/{ => obfuscated}/crasher/sample26.class (100%) rename src/test/resources/samples/{ => obfuscated}/crasher/sample27.class (100%) rename src/test/resources/samples/{ => obfuscated}/crasher/sample28.class (100%) rename src/test/resources/samples/{ => obfuscated}/crasher/sample29.class (100%) rename src/test/resources/samples/{ => obfuscated}/crasher/sample3.class (100%) rename src/test/resources/samples/{ => obfuscated}/crasher/sample4.class (100%) rename src/test/resources/samples/{ => obfuscated}/crasher/sample5.class (100%) rename src/test/resources/samples/{ => obfuscated}/crasher/sample6.class (100%) rename src/test/resources/samples/{ => obfuscated}/crasher/sample7.class (100%) rename src/test/resources/samples/{ => obfuscated}/crasher/sample8.class (100%) rename src/test/resources/samples/{ => obfuscated}/crasher/sample9.class (100%) diff --git a/src/test/java/me/coley/cafedude/CrasherPatchingTest.java b/src/test/java/me/coley/cafedude/CrasherPatchingTest.java index 90f790b..2518b42 100644 --- a/src/test/java/me/coley/cafedude/CrasherPatchingTest.java +++ b/src/test/java/me/coley/cafedude/CrasherPatchingTest.java @@ -61,7 +61,7 @@ public void testPatch(File sub) { */ public static List supply() { List files = new ArrayList<>(); - File root = new File("src/test/resources/samples/crasher"); + File root = new File("src/test/resources/samples/obfuscated/crasher"); for (File sub : Objects.requireNonNull(root.listFiles())) { if (sub.getName().endsWith(".class")) files.add(sub); diff --git a/src/test/java/me/coley/cafedude/EqualityIOTest.java b/src/test/java/me/coley/cafedude/EqualityIOTest.java index 1805dcb..bd0d111 100644 --- a/src/test/java/me/coley/cafedude/EqualityIOTest.java +++ b/src/test/java/me/coley/cafedude/EqualityIOTest.java @@ -3,12 +3,18 @@ import me.coley.cafedude.classfile.ClassFile; import me.coley.cafedude.io.ClassFileReader; import me.coley.cafedude.io.ClassFileWriter; -import org.junit.jupiter.api.Test; +import me.coley.cafedude.transform.IllegalStrippingTransformer; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; -import java.io.File; import java.io.IOException; import java.nio.file.Files; -import java.util.Objects; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.List; +import java.util.function.BiPredicate; +import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.*; @@ -16,47 +22,34 @@ * Test that asserts the classes that are read and written back to are identical. */ public class EqualityIOTest { - private File lastLoaded; - private int successes; - - @Test - public void testSamples() { + @ParameterizedTest + @MethodSource("supply") + public void testEquality(Path sub) { try { - visitRootDir("samples/annos"); - visitRootDir("samples/modules"); - visitRootDir("samples/javac"); - visitRootDir("samples/misc"); + byte[] code = Files.readAllBytes(sub); + ClassFile cf = new ClassFileReader().read(code); + new IllegalStrippingTransformer(cf).transform(); + byte[] out = new ClassFileWriter().write(cf); + assertEquals(code.length, out.length, "Class difference for: " + cf.getName()); + assertArrayEquals(code, out); } catch (IOException e) { - System.err.println(lastLoaded.getPath()); fail("Failed to read class, IO error", e); } catch (InvalidClassException e) { - System.err.println(lastLoaded.getPath()); fail("Failed to read class, invalid class", e); } - System.out.println("Successes: " + successes); - } - - private void assertReadWriteEquality(byte[] code) throws InvalidClassException { - ClassFile cf = new ClassFileReader().read(code); - byte[] out = new ClassFileWriter().write(cf); - assertEquals(code.length, out.length, "Class difference for: " + cf.getName()); - assertArrayEquals(code, out); } - private void visitRootDir(String dir) throws IOException, InvalidClassException { - File root = new File("src/test/resources/" + dir); - visit(root); - } - - private void visit(File file) throws IOException, InvalidClassException { - if (file.isDirectory()) { - for (File sub : Objects.requireNonNull(file.listFiles())) - visit(sub); - } else if (file.getName().endsWith(".class")) { - lastLoaded = file; - byte[] code = Files.readAllBytes(file.toPath()); - assertReadWriteEquality(code); - successes++; + /** + * @return Test files to check. + */ + public static List supply() { + try { + BiPredicate filter = + (path, attrib) -> attrib.isRegularFile() && path.toString().endsWith(".class"); + return Files.find(Paths.get("src/test/resources/samples/normal"), 25, filter) + .collect(Collectors.toList()); + } catch (IOException e) { + throw new RuntimeException(e); } } } diff --git a/src/test/resources/samples/annos/Anno.class b/src/test/resources/samples/normal/annos/Anno.class similarity index 100% rename from src/test/resources/samples/annos/Anno.class rename to src/test/resources/samples/normal/annos/Anno.class diff --git a/src/test/resources/samples/annos/Anno.java b/src/test/resources/samples/normal/annos/Anno.java similarity index 100% rename from src/test/resources/samples/annos/Anno.java rename to src/test/resources/samples/normal/annos/Anno.java diff --git a/src/test/resources/samples/normal/annos/CommandLine$Command.class b/src/test/resources/samples/normal/annos/CommandLine$Command.class new file mode 100644 index 0000000000000000000000000000000000000000..c135ca1cd6d35564337deede34f518340f2c3cb1 GIT binary patch literal 3535 zcma)8Yg-dn5S|5bi=ZOng{l>A2v~`B0i7%Zs?hOC3GyCYjnGm?awOTVWAyVJ-00^?%~Q|pSR#*Af39{ z6#K%d1ptkC)*824l_*jGmOH}W5dp&RloFrf_6D$UWB@oa|=AJIwhboyMQV-C``-VYJ02$SPi}+&zsWa+FB&%QaR@0sn?V_!P9TK(i)s-#_1qoa?fU| z7^-Jo^E!>`^buUB<_k~rPY}e-Ox-@OMtrq>jO-z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