diff options
Diffstat (limited to 'src/test')
9 files changed, 42 insertions, 42 deletions
diff --git a/src/test/java/cuchaz/enigma/PackageVisibilityIndexTest.java b/src/test/java/cuchaz/enigma/PackageVisibilityIndexTest.java index ae5d6d2..1dc9748 100644 --- a/src/test/java/cuchaz/enigma/PackageVisibilityIndexTest.java +++ b/src/test/java/cuchaz/enigma/PackageVisibilityIndexTest.java | |||
| @@ -11,13 +11,13 @@ | |||
| 11 | 11 | ||
| 12 | package cuchaz.enigma; | 12 | package cuchaz.enigma; |
| 13 | 13 | ||
| 14 | import cuchaz.enigma.analysis.ParsedJar; | 14 | import cuchaz.enigma.analysis.ClassCache; |
| 15 | import cuchaz.enigma.analysis.index.JarIndex; | 15 | import cuchaz.enigma.analysis.index.JarIndex; |
| 16 | import cuchaz.enigma.analysis.index.PackageVisibilityIndex; | 16 | import cuchaz.enigma.analysis.index.PackageVisibilityIndex; |
| 17 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | 17 | import cuchaz.enigma.translation.representation.entry.ClassEntry; |
| 18 | import org.junit.Test; | 18 | import org.junit.Test; |
| 19 | 19 | ||
| 20 | import java.util.jar.JarFile; | 20 | import java.nio.file.Paths; |
| 21 | 21 | ||
| 22 | import static cuchaz.enigma.TestEntryFactory.newClass; | 22 | import static cuchaz.enigma.TestEntryFactory.newClass; |
| 23 | import static org.hamcrest.MatcherAssert.assertThat; | 23 | import static org.hamcrest.MatcherAssert.assertThat; |
| @@ -35,10 +35,8 @@ public class PackageVisibilityIndexTest { | |||
| 35 | private final JarIndex jarIndex; | 35 | private final JarIndex jarIndex; |
| 36 | 36 | ||
| 37 | public PackageVisibilityIndexTest() throws Exception { | 37 | public PackageVisibilityIndexTest() throws Exception { |
| 38 | jarIndex = JarIndex.empty(); | 38 | ClassCache classCache = ClassCache.of(Paths.get("build/test-obf/packageAccess.jar")); |
| 39 | ParsedJar jar = new ParsedJar(new JarFile("build/test-obf/packageAccess.jar")); | 39 | jarIndex = classCache.index(ProgressListener.none()); |
| 40 | jarIndex.indexJar(jar, s -> { | ||
| 41 | }); | ||
| 42 | } | 40 | } |
| 43 | 41 | ||
| 44 | @Test | 42 | @Test |
diff --git a/src/test/java/cuchaz/enigma/TestDeobfed.java b/src/test/java/cuchaz/enigma/TestDeobfed.java index 14b1418..3d875df 100644 --- a/src/test/java/cuchaz/enigma/TestDeobfed.java +++ b/src/test/java/cuchaz/enigma/TestDeobfed.java | |||
| @@ -11,12 +11,12 @@ | |||
| 11 | 11 | ||
| 12 | package cuchaz.enigma; | 12 | package cuchaz.enigma; |
| 13 | 13 | ||
| 14 | import cuchaz.enigma.analysis.ParsedJar; | 14 | import cuchaz.enigma.analysis.ClassCache; |
| 15 | import cuchaz.enigma.analysis.index.JarIndex; | 15 | import cuchaz.enigma.analysis.index.JarIndex; |
| 16 | import org.junit.BeforeClass; | 16 | import org.junit.BeforeClass; |
| 17 | import org.junit.Test; | 17 | import org.junit.Test; |
| 18 | 18 | ||
| 19 | import java.util.jar.JarFile; | 19 | import java.nio.file.Paths; |
| 20 | 20 | ||
| 21 | import static cuchaz.enigma.TestEntryFactory.newClass; | 21 | import static cuchaz.enigma.TestEntryFactory.newClass; |
| 22 | import static org.hamcrest.MatcherAssert.assertThat; | 22 | import static org.hamcrest.MatcherAssert.assertThat; |
| @@ -24,15 +24,16 @@ import static org.hamcrest.Matchers.containsInAnyOrder; | |||
| 24 | 24 | ||
| 25 | public class TestDeobfed { | 25 | public class TestDeobfed { |
| 26 | 26 | ||
| 27 | private static ParsedJar jar; | 27 | private static Enigma enigma; |
| 28 | private static ClassCache classCache; | ||
| 28 | private static JarIndex index; | 29 | private static JarIndex index; |
| 29 | 30 | ||
| 30 | @BeforeClass | 31 | @BeforeClass |
| 31 | public static void beforeClass() | 32 | public static void beforeClass() throws Exception { |
| 32 | throws Exception { | 33 | enigma = Enigma.create(); |
| 33 | jar = new ParsedJar(new JarFile("build/test-deobf/translation.jar")); | 34 | |
| 34 | index = JarIndex.empty(); | 35 | classCache = ClassCache.of(Paths.get("build/test-deobf/translation.jar")); |
| 35 | index.indexJar(jar, s -> {}); | 36 | index = classCache.index(ProgressListener.none()); |
| 36 | } | 37 | } |
| 37 | 38 | ||
| 38 | @Test | 39 | @Test |
| @@ -67,8 +68,9 @@ public class TestDeobfed { | |||
| 67 | @Test | 68 | @Test |
| 68 | public void decompile() | 69 | public void decompile() |
| 69 | throws Exception { | 70 | throws Exception { |
| 70 | Deobfuscator deobfuscator = new Deobfuscator(jar); | 71 | EnigmaProject project = new EnigmaProject(enigma, classCache, index); |
| 71 | SourceProvider sourceProvider = deobfuscator.getObfSourceProvider(); | 72 | |
| 73 | SourceProvider sourceProvider = project.getObfSourceProvider(); | ||
| 72 | sourceProvider.getSources("a"); | 74 | sourceProvider.getSources("a"); |
| 73 | sourceProvider.getSources("b"); | 75 | sourceProvider.getSources("b"); |
| 74 | sourceProvider.getSources("c"); | 76 | sourceProvider.getSources("c"); |
diff --git a/src/test/java/cuchaz/enigma/TestDeobfuscator.java b/src/test/java/cuchaz/enigma/TestDeobfuscator.java index e070b66..5b9611c 100644 --- a/src/test/java/cuchaz/enigma/TestDeobfuscator.java +++ b/src/test/java/cuchaz/enigma/TestDeobfuscator.java | |||
| @@ -23,9 +23,9 @@ import static org.junit.Assert.assertEquals; | |||
| 23 | 23 | ||
| 24 | public class TestDeobfuscator { | 24 | public class TestDeobfuscator { |
| 25 | 25 | ||
| 26 | private Deobfuscator getDeobfuscator() | 26 | private Enigma getDeobfuscator() |
| 27 | throws IOException { | 27 | throws IOException { |
| 28 | return new Deobfuscator(new JarFile("build/test-obf/loneClass.jar")); | 28 | return new Enigma(new JarFile("build/test-obf/loneClass.jar")); |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | @Test | 31 | @Test |
| @@ -37,10 +37,10 @@ public class TestDeobfuscator { | |||
| 37 | @Test | 37 | @Test |
| 38 | public void getClasses() | 38 | public void getClasses() |
| 39 | throws Exception { | 39 | throws Exception { |
| 40 | Deobfuscator deobfuscator = getDeobfuscator(); | 40 | Enigma enigma = getDeobfuscator(); |
| 41 | List<ClassEntry> obfClasses = Lists.newArrayList(); | 41 | List<ClassEntry> obfClasses = Lists.newArrayList(); |
| 42 | List<ClassEntry> deobfClasses = Lists.newArrayList(); | 42 | List<ClassEntry> deobfClasses = Lists.newArrayList(); |
| 43 | deobfuscator.getSeparatedClasses(obfClasses, deobfClasses); | 43 | enigma.getSeparatedClasses(obfClasses, deobfClasses); |
| 44 | assertEquals(1, obfClasses.size()); | 44 | assertEquals(1, obfClasses.size()); |
| 45 | assertEquals("a", obfClasses.get(0).getName()); | 45 | assertEquals("a", obfClasses.get(0).getName()); |
| 46 | assertEquals(1, deobfClasses.size()); | 46 | assertEquals(1, deobfClasses.size()); |
| @@ -50,8 +50,8 @@ public class TestDeobfuscator { | |||
| 50 | @Test | 50 | @Test |
| 51 | public void decompileClass() | 51 | public void decompileClass() |
| 52 | throws Exception { | 52 | throws Exception { |
| 53 | Deobfuscator deobfuscator = getDeobfuscator(); | 53 | Enigma enigma = getDeobfuscator(); |
| 54 | SourceProvider sourceProvider = deobfuscator.getObfSourceProvider(); | 54 | SourceProvider sourceProvider = enigma.getObfSourceProvider(); |
| 55 | sourceProvider.writeSourceToString(sourceProvider.getSources("a")); | 55 | sourceProvider.writeSourceToString(sourceProvider.getSources("a")); |
| 56 | } | 56 | } |
| 57 | } | 57 | } |
diff --git a/src/test/java/cuchaz/enigma/TestInnerClasses.java b/src/test/java/cuchaz/enigma/TestInnerClasses.java index 8738fd7..b6e4e2d 100644 --- a/src/test/java/cuchaz/enigma/TestInnerClasses.java +++ b/src/test/java/cuchaz/enigma/TestInnerClasses.java | |||
| @@ -11,11 +11,12 @@ | |||
| 11 | 11 | ||
| 12 | package cuchaz.enigma; | 12 | package cuchaz.enigma; |
| 13 | 13 | ||
| 14 | import cuchaz.enigma.analysis.ParsedJar; | 14 | import cuchaz.enigma.analysis.ClassCache; |
| 15 | import cuchaz.enigma.analysis.index.JarIndex; | 15 | import cuchaz.enigma.analysis.index.JarIndex; |
| 16 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | 16 | import cuchaz.enigma.translation.representation.entry.ClassEntry; |
| 17 | import org.junit.Test; | 17 | import org.junit.Test; |
| 18 | 18 | ||
| 19 | import java.nio.file.Paths; | ||
| 19 | import java.util.jar.JarFile; | 20 | import java.util.jar.JarFile; |
| 20 | 21 | ||
| 21 | import static cuchaz.enigma.TestEntryFactory.newClass; | 22 | import static cuchaz.enigma.TestEntryFactory.newClass; |
| @@ -33,14 +34,14 @@ public class TestInnerClasses { | |||
| 33 | private static final ClassEntry ClassTreeLevel2 = newClass("f$a$a"); | 34 | private static final ClassEntry ClassTreeLevel2 = newClass("f$a$a"); |
| 34 | private static final ClassEntry ClassTreeLevel3 = newClass("f$a$a$a"); | 35 | private static final ClassEntry ClassTreeLevel3 = newClass("f$a$a$a"); |
| 35 | private JarIndex index; | 36 | private JarIndex index; |
| 36 | private Deobfuscator deobfuscator; | 37 | private Enigma enigma; |
| 37 | 38 | ||
| 38 | public TestInnerClasses() | 39 | public TestInnerClasses() |
| 39 | throws Exception { | 40 | throws Exception { |
| 40 | index = JarIndex.empty(); | 41 | ClassCache classCache = ClassCache.of(Paths.get("build/test-obf/innerClasses.jar")); |
| 41 | ParsedJar jar = new ParsedJar(new JarFile("build/test-obf/innerClasses.jar")); | 42 | index = classCache.index(ProgressListener.none()); |
| 42 | index.indexJar(jar, s -> {}); | 43 | |
| 43 | deobfuscator = new Deobfuscator(jar); | 44 | enigma = new Enigma(jar); |
| 44 | } | 45 | } |
| 45 | 46 | ||
| 46 | @Test | 47 | @Test |
| @@ -79,6 +80,6 @@ public class TestInnerClasses { | |||
| 79 | } | 80 | } |
| 80 | 81 | ||
| 81 | private void decompile(ClassEntry classEntry) { | 82 | private void decompile(ClassEntry classEntry) { |
| 82 | deobfuscator.getObfSourceProvider().getSources(classEntry.getName()); | 83 | enigma.getObfSourceProvider().getSources(classEntry.getName()); |
| 83 | } | 84 | } |
| 84 | } | 85 | } |
diff --git a/src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java b/src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java index c3f3b66..0712ccf 100644 --- a/src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java +++ b/src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java | |||
| @@ -12,7 +12,6 @@ | |||
| 12 | package cuchaz.enigma; | 12 | package cuchaz.enigma; |
| 13 | 13 | ||
| 14 | import cuchaz.enigma.analysis.EntryReference; | 14 | import cuchaz.enigma.analysis.EntryReference; |
| 15 | import cuchaz.enigma.analysis.ParsedJar; | ||
| 16 | import cuchaz.enigma.analysis.index.JarIndex; | 15 | import cuchaz.enigma.analysis.index.JarIndex; |
| 17 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | 16 | import cuchaz.enigma.translation.representation.entry.ClassEntry; |
| 18 | import cuchaz.enigma.translation.representation.entry.MethodDefEntry; | 17 | import cuchaz.enigma.translation.representation.entry.MethodDefEntry; |
diff --git a/src/test/java/cuchaz/enigma/TestJarIndexInheritanceTree.java b/src/test/java/cuchaz/enigma/TestJarIndexInheritanceTree.java index 36595a3..76e379c 100644 --- a/src/test/java/cuchaz/enigma/TestJarIndexInheritanceTree.java +++ b/src/test/java/cuchaz/enigma/TestJarIndexInheritanceTree.java | |||
| @@ -11,8 +11,8 @@ | |||
| 11 | 11 | ||
| 12 | package cuchaz.enigma; | 12 | package cuchaz.enigma; |
| 13 | 13 | ||
| 14 | import cuchaz.enigma.analysis.ClassCache; | ||
| 14 | import cuchaz.enigma.analysis.EntryReference; | 15 | import cuchaz.enigma.analysis.EntryReference; |
| 15 | import cuchaz.enigma.analysis.ParsedJar; | ||
| 16 | import cuchaz.enigma.analysis.index.EntryIndex; | 16 | import cuchaz.enigma.analysis.index.EntryIndex; |
| 17 | import cuchaz.enigma.analysis.index.InheritanceIndex; | 17 | import cuchaz.enigma.analysis.index.InheritanceIndex; |
| 18 | import cuchaz.enigma.analysis.index.JarIndex; | 18 | import cuchaz.enigma.analysis.index.JarIndex; |
| @@ -26,8 +26,8 @@ import cuchaz.enigma.translation.representation.entry.MethodEntry; | |||
| 26 | import org.junit.Test; | 26 | import org.junit.Test; |
| 27 | import org.objectweb.asm.Opcodes; | 27 | import org.objectweb.asm.Opcodes; |
| 28 | 28 | ||
| 29 | import java.nio.file.Paths; | ||
| 29 | import java.util.Collection; | 30 | import java.util.Collection; |
| 30 | import java.util.jar.JarFile; | ||
| 31 | 31 | ||
| 32 | import static cuchaz.enigma.TestEntryFactory.*; | 32 | import static cuchaz.enigma.TestEntryFactory.*; |
| 33 | import static org.hamcrest.MatcherAssert.assertThat; | 33 | import static org.hamcrest.MatcherAssert.assertThat; |
| @@ -46,8 +46,8 @@ public class TestJarIndexInheritanceTree { | |||
| 46 | 46 | ||
| 47 | public TestJarIndexInheritanceTree() | 47 | public TestJarIndexInheritanceTree() |
| 48 | throws Exception { | 48 | throws Exception { |
| 49 | index = JarIndex.empty(); | 49 | ClassCache classCache = ClassCache.of(Paths.get("build/test-obf/inheritanceTree.jar")); |
| 50 | index.indexJar(new ParsedJar(new JarFile("build/test-obf/inheritanceTree.jar")), s -> {}); | 50 | index = classCache.index(ProgressListener.none()); |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | @Test | 53 | @Test |
diff --git a/src/test/java/cuchaz/enigma/TestSourceIndex.java b/src/test/java/cuchaz/enigma/TestSourceIndex.java index ce5d631..8a604f8 100644 --- a/src/test/java/cuchaz/enigma/TestSourceIndex.java +++ b/src/test/java/cuchaz/enigma/TestSourceIndex.java | |||
| @@ -41,17 +41,17 @@ public class TestSourceIndex { | |||
| 41 | mcJar = new File(mcDir, "versions/1.8.3/1.8.3.jar"); | 41 | mcJar = new File(mcDir, "versions/1.8.3/1.8.3.jar"); |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | Deobfuscator deobfuscator = new Deobfuscator(new JarFile(mcJar)); | 44 | Enigma enigma = new Enigma(new JarFile(mcJar)); |
| 45 | 45 | ||
| 46 | // get all classes that aren't inner classes | 46 | // get all classes that aren't inner classes |
| 47 | Set<ClassEntry> classEntries = Sets.newHashSet(); | 47 | Set<ClassEntry> classEntries = Sets.newHashSet(); |
| 48 | for (ClassEntry obfClassEntry : deobfuscator.getJarIndex().getEntryIndex().getClasses()) { | 48 | for (ClassEntry obfClassEntry : enigma.getJarIndex().getEntryIndex().getClasses()) { |
| 49 | if (!obfClassEntry.isInnerClass()) { | 49 | if (!obfClassEntry.isInnerClass()) { |
| 50 | classEntries.add(obfClassEntry); | 50 | classEntries.add(obfClassEntry); |
| 51 | } | 51 | } |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | SourceProvider sourceProvider = deobfuscator.getObfSourceProvider(); | 54 | SourceProvider sourceProvider = enigma.getObfSourceProvider(); |
| 55 | for (ClassEntry obfClassEntry : classEntries) { | 55 | for (ClassEntry obfClassEntry : classEntries) { |
| 56 | try { | 56 | try { |
| 57 | CompilationUnit tree = sourceProvider.getSources(obfClassEntry.getName()); | 57 | CompilationUnit tree = sourceProvider.getSources(obfClassEntry.getName()); |
diff --git a/src/test/java/cuchaz/enigma/TestTranslator.java b/src/test/java/cuchaz/enigma/TestTranslator.java index b978129..a420afe 100644 --- a/src/test/java/cuchaz/enigma/TestTranslator.java +++ b/src/test/java/cuchaz/enigma/TestTranslator.java | |||
| @@ -23,7 +23,7 @@ public class TestTranslator { | |||
| 23 | public static void beforeClass() | 23 | public static void beforeClass() |
| 24 | throws Exception { | 24 | throws Exception { |
| 25 | //TODO FIx | 25 | //TODO FIx |
| 26 | //deobfuscator = new Deobfuscator(new JarFile("build/test-obf/translation.jar")); | 26 | //deobfuscator = new Enigma(new JarFile("build/test-obf/translation.jar")); |
| 27 | //try (InputStream in = TestTranslator.class.getResourceAsStream("/cuchaz/enigma/resources/translation.mappings")) { | 27 | //try (InputStream in = TestTranslator.class.getResourceAsStream("/cuchaz/enigma/resources/translation.mappings")) { |
| 28 | // mappings = new MappingsJsonReader().read(new InputStreamReader(in)); | 28 | // mappings = new MappingsJsonReader().read(new InputStreamReader(in)); |
| 29 | // deobfuscator.setMappings(mappings); | 29 | // deobfuscator.setMappings(mappings); |
diff --git a/src/test/java/cuchaz/enigma/TokenChecker.java b/src/test/java/cuchaz/enigma/TokenChecker.java index c4670a2..9e0c696 100644 --- a/src/test/java/cuchaz/enigma/TokenChecker.java +++ b/src/test/java/cuchaz/enigma/TokenChecker.java | |||
| @@ -25,16 +25,16 @@ import java.util.jar.JarFile; | |||
| 25 | 25 | ||
| 26 | public class TokenChecker { | 26 | public class TokenChecker { |
| 27 | 27 | ||
| 28 | private Deobfuscator deobfuscator; | 28 | private Enigma enigma; |
| 29 | 29 | ||
| 30 | protected TokenChecker(JarFile jarFile) | 30 | protected TokenChecker(JarFile jarFile) |
| 31 | throws IOException { | 31 | throws IOException { |
| 32 | deobfuscator = new Deobfuscator(jarFile); | 32 | enigma = new Enigma(jarFile); |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | protected String getDeclarationToken(Entry<?> entry) { | 35 | protected String getDeclarationToken(Entry<?> entry) { |
| 36 | // decompile the class | 36 | // decompile the class |
| 37 | SourceProvider sourceProvider = deobfuscator.getObfSourceProvider(); | 37 | SourceProvider sourceProvider = enigma.getObfSourceProvider(); |
| 38 | CompilationUnit tree = sourceProvider.getSources(entry.getContainingClass().getFullName()); | 38 | CompilationUnit tree = sourceProvider.getSources(entry.getContainingClass().getFullName()); |
| 39 | // DEBUG | 39 | // DEBUG |
| 40 | // tree.acceptVisitor( new TreeDumpVisitor( new File( "tree." + entry.getClassName().replace( '/', '.' ) + ".txt" ) ), null ); | 40 | // tree.acceptVisitor( new TreeDumpVisitor( new File( "tree." + entry.getClassName().replace( '/', '.' ) + ".txt" ) ), null ); |
| @@ -52,7 +52,7 @@ public class TokenChecker { | |||
| 52 | @SuppressWarnings("unchecked") | 52 | @SuppressWarnings("unchecked") |
| 53 | protected Collection<String> getReferenceTokens(EntryReference<? extends Entry<?>, ? extends Entry<?>> reference) { | 53 | protected Collection<String> getReferenceTokens(EntryReference<? extends Entry<?>, ? extends Entry<?>> reference) { |
| 54 | // decompile the class | 54 | // decompile the class |
| 55 | SourceProvider sourceProvider = deobfuscator.getObfSourceProvider(); | 55 | SourceProvider sourceProvider = enigma.getObfSourceProvider(); |
| 56 | CompilationUnit tree = sourceProvider.getSources(reference.context.getContainingClass().getFullName()); | 56 | CompilationUnit tree = sourceProvider.getSources(reference.context.getContainingClass().getFullName()); |
| 57 | String source = sourceProvider.writeSourceToString(tree); | 57 | String source = sourceProvider.writeSourceToString(tree); |
| 58 | SourceIndex index = SourceIndex.buildIndex(source, tree, true); | 58 | SourceIndex index = SourceIndex.buildIndex(source, tree, true); |