diff options
| author | 2019-06-19 18:51:31 +0100 | |
|---|---|---|
| committer | 2019-06-19 18:51:31 +0100 | |
| commit | 546c617598b10c341fe6549678803f6ac0c95619 (patch) | |
| tree | d818bcebf7634ed5b716ee29619725fdc29a04e8 /src/test | |
| parent | fix unwanted declaration navigation during Quick Find (diff) | |
| parent | Parse profile json from cli args (diff) | |
| download | enigma-546c617598b10c341fe6549678803f6ac0c95619.tar.gz enigma-546c617598b10c341fe6549678803f6ac0c95619.tar.xz enigma-546c617598b10c341fe6549678803f6ac0c95619.zip | |
Merge pull request #135 from gegy1000/proposal-tweak
Plugin rework
Diffstat (limited to 'src/test')
11 files changed, 86 insertions, 92 deletions
diff --git a/src/test/java/cuchaz/enigma/PackageVisibilityIndexTest.java b/src/test/java/cuchaz/enigma/PackageVisibilityIndexTest.java index ae5d6d2c..1dc9748b 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 14b1418d..3ee86cb7 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 |
| @@ -65,10 +66,12 @@ public class TestDeobfed { | |||
| 65 | } | 66 | } |
| 66 | 67 | ||
| 67 | @Test | 68 | @Test |
| 68 | public void decompile() | 69 | public void decompile() { |
| 69 | throws Exception { | 70 | EnigmaProject project = new EnigmaProject(enigma, classCache, index); |
| 70 | Deobfuscator deobfuscator = new Deobfuscator(jar); | 71 | |
| 71 | SourceProvider sourceProvider = deobfuscator.getObfSourceProvider(); | 72 | CompiledSourceTypeLoader typeLoader = new CompiledSourceTypeLoader(project.getClassCache()); |
| 73 | SourceProvider sourceProvider = new SourceProvider(SourceProvider.createSettings(), typeLoader); | ||
| 74 | |||
| 72 | sourceProvider.getSources("a"); | 75 | sourceProvider.getSources("a"); |
| 73 | sourceProvider.getSources("b"); | 76 | sourceProvider.getSources("b"); |
| 74 | sourceProvider.getSources("c"); | 77 | sourceProvider.getSources("c"); |
diff --git a/src/test/java/cuchaz/enigma/TestDeobfuscator.java b/src/test/java/cuchaz/enigma/TestDeobfuscator.java index e070b66f..2a6fec49 100644 --- a/src/test/java/cuchaz/enigma/TestDeobfuscator.java +++ b/src/test/java/cuchaz/enigma/TestDeobfuscator.java | |||
| @@ -11,47 +11,31 @@ | |||
| 11 | 11 | ||
| 12 | package cuchaz.enigma; | 12 | package cuchaz.enigma; |
| 13 | 13 | ||
| 14 | import com.google.common.collect.Lists; | ||
| 15 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | ||
| 16 | import org.junit.Test; | 14 | import org.junit.Test; |
| 17 | 15 | ||
| 18 | import java.io.IOException; | 16 | import java.io.IOException; |
| 19 | import java.util.List; | 17 | import java.nio.file.Paths; |
| 20 | import java.util.jar.JarFile; | ||
| 21 | |||
| 22 | import static org.junit.Assert.assertEquals; | ||
| 23 | 18 | ||
| 24 | public class TestDeobfuscator { | 19 | public class TestDeobfuscator { |
| 25 | 20 | ||
| 26 | private Deobfuscator getDeobfuscator() | 21 | private EnigmaProject openProject() throws IOException { |
| 27 | throws IOException { | 22 | Enigma enigma = Enigma.create(); |
| 28 | return new Deobfuscator(new JarFile("build/test-obf/loneClass.jar")); | 23 | return enigma.openJar(Paths.get("build/test-obf/loneClass.jar"), ProgressListener.none()); |
| 29 | } | 24 | } |
| 30 | 25 | ||
| 31 | @Test | 26 | @Test |
| 32 | public void loadJar() | 27 | public void loadJar() |
| 33 | throws Exception { | 28 | throws Exception { |
| 34 | getDeobfuscator(); | 29 | openProject(); |
| 35 | } | 30 | } |
| 36 | 31 | ||
| 37 | @Test | 32 | @Test |
| 38 | public void getClasses() | 33 | public void decompileClass() throws Exception { |
| 39 | throws Exception { | 34 | EnigmaProject project = openProject(); |
| 40 | Deobfuscator deobfuscator = getDeobfuscator(); | 35 | |
| 41 | List<ClassEntry> obfClasses = Lists.newArrayList(); | 36 | CompiledSourceTypeLoader typeLoader = new CompiledSourceTypeLoader(project.getClassCache()); |
| 42 | List<ClassEntry> deobfClasses = Lists.newArrayList(); | 37 | SourceProvider sourceProvider = new SourceProvider(SourceProvider.createSettings(), typeLoader); |
| 43 | deobfuscator.getSeparatedClasses(obfClasses, deobfClasses); | ||
| 44 | assertEquals(1, obfClasses.size()); | ||
| 45 | assertEquals("a", obfClasses.get(0).getName()); | ||
| 46 | assertEquals(1, deobfClasses.size()); | ||
| 47 | assertEquals("cuchaz/enigma/inputs/Keep", deobfClasses.get(0).getName()); | ||
| 48 | } | ||
| 49 | 38 | ||
| 50 | @Test | ||
| 51 | public void decompileClass() | ||
| 52 | throws Exception { | ||
| 53 | Deobfuscator deobfuscator = getDeobfuscator(); | ||
| 54 | SourceProvider sourceProvider = deobfuscator.getObfSourceProvider(); | ||
| 55 | sourceProvider.writeSourceToString(sourceProvider.getSources("a")); | 39 | sourceProvider.writeSourceToString(sourceProvider.getSources("a")); |
| 56 | } | 40 | } |
| 57 | } | 41 | } |
diff --git a/src/test/java/cuchaz/enigma/TestInnerClasses.java b/src/test/java/cuchaz/enigma/TestInnerClasses.java index 8738fd79..18e49369 100644 --- a/src/test/java/cuchaz/enigma/TestInnerClasses.java +++ b/src/test/java/cuchaz/enigma/TestInnerClasses.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 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.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; |
| @@ -33,14 +33,14 @@ public class TestInnerClasses { | |||
| 33 | private static final ClassEntry ClassTreeLevel2 = newClass("f$a$a"); | 33 | private static final ClassEntry ClassTreeLevel2 = newClass("f$a$a"); |
| 34 | private static final ClassEntry ClassTreeLevel3 = newClass("f$a$a$a"); | 34 | private static final ClassEntry ClassTreeLevel3 = newClass("f$a$a$a"); |
| 35 | private JarIndex index; | 35 | private JarIndex index; |
| 36 | private Deobfuscator deobfuscator; | 36 | private SourceProvider sourceProvider; |
| 37 | 37 | ||
| 38 | public TestInnerClasses() | 38 | public TestInnerClasses() throws Exception { |
| 39 | throws Exception { | 39 | ClassCache classCache = ClassCache.of(Paths.get("build/test-obf/innerClasses.jar")); |
| 40 | index = JarIndex.empty(); | 40 | index = classCache.index(ProgressListener.none()); |
| 41 | ParsedJar jar = new ParsedJar(new JarFile("build/test-obf/innerClasses.jar")); | 41 | |
| 42 | index.indexJar(jar, s -> {}); | 42 | CompiledSourceTypeLoader typeLoader = new CompiledSourceTypeLoader(classCache); |
| 43 | deobfuscator = new Deobfuscator(jar); | 43 | sourceProvider = new SourceProvider(SourceProvider.createSettings(), typeLoader); |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | @Test | 46 | @Test |
| @@ -79,6 +79,6 @@ public class TestInnerClasses { | |||
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | private void decompile(ClassEntry classEntry) { | 81 | private void decompile(ClassEntry classEntry) { |
| 82 | deobfuscator.getObfSourceProvider().getSources(classEntry.getName()); | 82 | sourceProvider.getSources(classEntry.getName()); |
| 83 | } | 83 | } |
| 84 | } | 84 | } |
diff --git a/src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java b/src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java index c3f3b669..48975c82 100644 --- a/src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java +++ b/src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java | |||
| @@ -11,17 +11,16 @@ | |||
| 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.JarIndex; | 16 | import cuchaz.enigma.analysis.index.JarIndex; |
| 17 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | 17 | import cuchaz.enigma.translation.representation.entry.ClassEntry; |
| 18 | import cuchaz.enigma.translation.representation.entry.MethodDefEntry; | 18 | import cuchaz.enigma.translation.representation.entry.MethodDefEntry; |
| 19 | import cuchaz.enigma.translation.representation.entry.MethodEntry; | 19 | import cuchaz.enigma.translation.representation.entry.MethodEntry; |
| 20 | import org.junit.Test; | 20 | import org.junit.Test; |
| 21 | 21 | ||
| 22 | import java.io.File; | 22 | import java.nio.file.Paths; |
| 23 | import java.util.Collection; | 23 | import java.util.Collection; |
| 24 | import java.util.jar.JarFile; | ||
| 25 | 24 | ||
| 26 | import static cuchaz.enigma.TestEntryFactory.*; | 25 | import static cuchaz.enigma.TestEntryFactory.*; |
| 27 | import static org.hamcrest.MatcherAssert.assertThat; | 26 | import static org.hamcrest.MatcherAssert.assertThat; |
| @@ -37,11 +36,9 @@ public class TestJarIndexConstructorReferences { | |||
| 37 | private ClassEntry defaultClass = newClass("c"); | 36 | private ClassEntry defaultClass = newClass("c"); |
| 38 | private ClassEntry callerClass = newClass("b"); | 37 | private ClassEntry callerClass = newClass("b"); |
| 39 | 38 | ||
| 40 | public TestJarIndexConstructorReferences() | 39 | public TestJarIndexConstructorReferences() throws Exception { |
| 41 | throws Exception { | 40 | ClassCache classCache = ClassCache.of(Paths.get("build/test-obf/constructors.jar")); |
| 42 | File jarFile = new File("build/test-obf/constructors.jar"); | 41 | index = classCache.index(ProgressListener.none()); |
| 43 | index = JarIndex.empty(); | ||
| 44 | index.indexJar(new ParsedJar(new JarFile(jarFile)), s -> {}); | ||
| 45 | } | 42 | } |
| 46 | 43 | ||
| 47 | @Test | 44 | @Test |
diff --git a/src/test/java/cuchaz/enigma/TestJarIndexInheritanceTree.java b/src/test/java/cuchaz/enigma/TestJarIndexInheritanceTree.java index 36595a3b..76e379c3 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/TestJarIndexLoneClass.java b/src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java index 1299bccc..103c366b 100644 --- a/src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java +++ b/src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java | |||
| @@ -23,9 +23,9 @@ import cuchaz.enigma.translation.representation.entry.MethodDefEntry; | |||
| 23 | import cuchaz.enigma.translation.representation.entry.MethodEntry; | 23 | import cuchaz.enigma.translation.representation.entry.MethodEntry; |
| 24 | import org.junit.Test; | 24 | import org.junit.Test; |
| 25 | 25 | ||
| 26 | import java.nio.file.Paths; | ||
| 26 | import java.util.Collection; | 27 | import java.util.Collection; |
| 27 | import java.util.List; | 28 | import java.util.List; |
| 28 | import java.util.jar.JarFile; | ||
| 29 | 29 | ||
| 30 | import static cuchaz.enigma.TestEntryFactory.*; | 30 | import static cuchaz.enigma.TestEntryFactory.*; |
| 31 | import static org.hamcrest.MatcherAssert.assertThat; | 31 | import static org.hamcrest.MatcherAssert.assertThat; |
| @@ -35,10 +35,9 @@ public class TestJarIndexLoneClass { | |||
| 35 | 35 | ||
| 36 | private JarIndex index; | 36 | private JarIndex index; |
| 37 | 37 | ||
| 38 | public TestJarIndexLoneClass() | 38 | public TestJarIndexLoneClass() throws Exception { |
| 39 | throws Exception { | 39 | ClassCache classCache = ClassCache.of(Paths.get("build/test-obf/loneClass.jar")); |
| 40 | index = JarIndex.empty(); | 40 | index = classCache.index(ProgressListener.none()); |
| 41 | index.indexJar(new ParsedJar(new JarFile("build/test-obf/loneClass.jar")), s -> {}); | ||
| 42 | } | 41 | } |
| 43 | 42 | ||
| 44 | @Test | 43 | @Test |
diff --git a/src/test/java/cuchaz/enigma/TestSourceIndex.java b/src/test/java/cuchaz/enigma/TestSourceIndex.java index ce5d6316..b1d11822 100644 --- a/src/test/java/cuchaz/enigma/TestSourceIndex.java +++ b/src/test/java/cuchaz/enigma/TestSourceIndex.java | |||
| @@ -13,13 +13,15 @@ package cuchaz.enigma; | |||
| 13 | 13 | ||
| 14 | import com.google.common.collect.Sets; | 14 | import com.google.common.collect.Sets; |
| 15 | import com.strobel.decompiler.languages.java.ast.CompilationUnit; | 15 | import com.strobel.decompiler.languages.java.ast.CompilationUnit; |
| 16 | import cuchaz.enigma.analysis.ClassCache; | ||
| 16 | import cuchaz.enigma.analysis.SourceIndex; | 17 | import cuchaz.enigma.analysis.SourceIndex; |
| 18 | import cuchaz.enigma.analysis.index.JarIndex; | ||
| 17 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | 19 | import cuchaz.enigma.translation.representation.entry.ClassEntry; |
| 18 | import org.junit.Test; | 20 | import org.junit.Test; |
| 19 | 21 | ||
| 20 | import java.io.File; | 22 | import java.nio.file.Path; |
| 23 | import java.nio.file.Paths; | ||
| 21 | import java.util.Set; | 24 | import java.util.Set; |
| 22 | import java.util.jar.JarFile; | ||
| 23 | 25 | ||
| 24 | public class TestSourceIndex { | 26 | public class TestSourceIndex { |
| 25 | @Test | 27 | @Test |
| @@ -27,31 +29,41 @@ public class TestSourceIndex { | |||
| 27 | throws Exception { | 29 | throws Exception { |
| 28 | // Figure out where Minecraft is... | 30 | // Figure out where Minecraft is... |
| 29 | final String mcDir = System.getProperty("enigma.test.minecraftdir"); | 31 | final String mcDir = System.getProperty("enigma.test.minecraftdir"); |
| 30 | File mcJar = null; | 32 | Path mcJar = null; |
| 31 | if (mcDir == null) { | 33 | if (mcDir == null) { |
| 32 | String osname = System.getProperty("os.name").toLowerCase(); | 34 | String osname = System.getProperty("os.name").toLowerCase(); |
| 33 | if (osname.contains("nix") || osname.contains("nux") || osname.contains("solaris")) { | 35 | if (osname.contains("nix") || osname.contains("nux") || osname.contains("solaris")) { |
| 34 | mcJar = new File(System.getProperty("user.home"), ".minecraft/versions/1.8.3/1.8.3.jar"); | 36 | mcJar = Paths.get(System.getProperty("user.home"), ".minecraft/versions/1.8.3/1.8.3.jar"); |
| 35 | } else if (osname.contains("mac") || osname.contains("darwin")) { | 37 | } else if (osname.contains("mac") || osname.contains("darwin")) { |
| 36 | mcJar = new File(System.getProperty("user.home"), "Library/Application Support/minecraft/versions/1.8.3/1.8.3.jar"); | 38 | mcJar = Paths.get(System.getProperty("user.home"), "Library/Application Support/minecraft/versions/1.8.3/1.8.3.jar"); |
| 37 | } else if (osname.contains("win")) { | 39 | } else if (osname.contains("win")) { |
| 38 | mcJar = new File(System.getenv("AppData"), ".minecraft/versions/1.8.3/1.8.3.jar"); | 40 | mcJar = Paths.get(System.getenv("AppData"), ".minecraft/versions/1.8.3/1.8.3.jar"); |
| 39 | } | 41 | } |
| 40 | } else { | 42 | } else { |
| 41 | mcJar = new File(mcDir, "versions/1.8.3/1.8.3.jar"); | 43 | mcJar = Paths.get(mcDir, "versions/1.8.3/1.8.3.jar"); |
| 42 | } | 44 | } |
| 43 | 45 | ||
| 44 | Deobfuscator deobfuscator = new Deobfuscator(new JarFile(mcJar)); | 46 | if (mcJar == null) { |
| 47 | throw new NullPointerException("Couldn't find jar"); | ||
| 48 | } | ||
| 49 | |||
| 50 | Enigma enigma = Enigma.create(); | ||
| 51 | EnigmaProject project = enigma.openJar(mcJar, ProgressListener.none()); | ||
| 52 | |||
| 53 | ClassCache classCache = project.getClassCache(); | ||
| 54 | JarIndex index = project.getJarIndex(); | ||
| 55 | |||
| 56 | CompiledSourceTypeLoader typeLoader = new CompiledSourceTypeLoader(classCache); | ||
| 57 | SourceProvider sourceProvider = new SourceProvider(SourceProvider.createSettings(), typeLoader); | ||
| 45 | 58 | ||
| 46 | // get all classes that aren't inner classes | 59 | // get all classes that aren't inner classes |
| 47 | Set<ClassEntry> classEntries = Sets.newHashSet(); | 60 | Set<ClassEntry> classEntries = Sets.newHashSet(); |
| 48 | for (ClassEntry obfClassEntry : deobfuscator.getJarIndex().getEntryIndex().getClasses()) { | 61 | for (ClassEntry obfClassEntry : index.getEntryIndex().getClasses()) { |
| 49 | if (!obfClassEntry.isInnerClass()) { | 62 | if (!obfClassEntry.isInnerClass()) { |
| 50 | classEntries.add(obfClassEntry); | 63 | classEntries.add(obfClassEntry); |
| 51 | } | 64 | } |
| 52 | } | 65 | } |
| 53 | 66 | ||
| 54 | SourceProvider sourceProvider = deobfuscator.getObfSourceProvider(); | ||
| 55 | for (ClassEntry obfClassEntry : classEntries) { | 67 | for (ClassEntry obfClassEntry : classEntries) { |
| 56 | try { | 68 | try { |
| 57 | CompilationUnit tree = sourceProvider.getSources(obfClassEntry.getName()); | 69 | CompilationUnit tree = sourceProvider.getSources(obfClassEntry.getName()); |
diff --git a/src/test/java/cuchaz/enigma/TestTokensConstructors.java b/src/test/java/cuchaz/enigma/TestTokensConstructors.java index 1ee0bde1..0398de4f 100644 --- a/src/test/java/cuchaz/enigma/TestTokensConstructors.java +++ b/src/test/java/cuchaz/enigma/TestTokensConstructors.java | |||
| @@ -14,7 +14,7 @@ package cuchaz.enigma; | |||
| 14 | import cuchaz.enigma.translation.representation.entry.MethodEntry; | 14 | import cuchaz.enigma.translation.representation.entry.MethodEntry; |
| 15 | import org.junit.Test; | 15 | import org.junit.Test; |
| 16 | 16 | ||
| 17 | import java.util.jar.JarFile; | 17 | import java.nio.file.Paths; |
| 18 | 18 | ||
| 19 | import static cuchaz.enigma.TestEntryFactory.newBehaviorReferenceByMethod; | 19 | import static cuchaz.enigma.TestEntryFactory.newBehaviorReferenceByMethod; |
| 20 | import static cuchaz.enigma.TestEntryFactory.newMethod; | 20 | import static cuchaz.enigma.TestEntryFactory.newMethod; |
| @@ -25,7 +25,7 @@ public class TestTokensConstructors extends TokenChecker { | |||
| 25 | 25 | ||
| 26 | public TestTokensConstructors() | 26 | public TestTokensConstructors() |
| 27 | throws Exception { | 27 | throws Exception { |
| 28 | super(new JarFile("build/test-obf/constructors.jar")); | 28 | super(Paths.get("build/test-obf/constructors.jar")); |
| 29 | } | 29 | } |
| 30 | 30 | ||
| 31 | @Test | 31 | @Test |
diff --git a/src/test/java/cuchaz/enigma/TestTranslator.java b/src/test/java/cuchaz/enigma/TestTranslator.java index b9781297..a420afe1 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 c4670a20..1dde0349 100644 --- a/src/test/java/cuchaz/enigma/TokenChecker.java +++ b/src/test/java/cuchaz/enigma/TokenChecker.java | |||
| @@ -13,28 +13,30 @@ package cuchaz.enigma; | |||
| 13 | 13 | ||
| 14 | import com.google.common.collect.Lists; | 14 | import com.google.common.collect.Lists; |
| 15 | import com.strobel.decompiler.languages.java.ast.CompilationUnit; | 15 | import com.strobel.decompiler.languages.java.ast.CompilationUnit; |
| 16 | import cuchaz.enigma.analysis.ClassCache; | ||
| 16 | import cuchaz.enigma.analysis.EntryReference; | 17 | import cuchaz.enigma.analysis.EntryReference; |
| 17 | import cuchaz.enigma.analysis.SourceIndex; | 18 | import cuchaz.enigma.analysis.SourceIndex; |
| 18 | import cuchaz.enigma.analysis.Token; | 19 | import cuchaz.enigma.analysis.Token; |
| 19 | import cuchaz.enigma.translation.representation.entry.Entry; | 20 | import cuchaz.enigma.translation.representation.entry.Entry; |
| 20 | 21 | ||
| 21 | import java.io.IOException; | 22 | import java.io.IOException; |
| 23 | import java.nio.file.Path; | ||
| 22 | import java.util.Collection; | 24 | import java.util.Collection; |
| 23 | import java.util.List; | 25 | import java.util.List; |
| 24 | import java.util.jar.JarFile; | ||
| 25 | 26 | ||
| 26 | public class TokenChecker { | 27 | public class TokenChecker { |
| 27 | 28 | ||
| 28 | private Deobfuscator deobfuscator; | 29 | private SourceProvider sourceProvider; |
| 29 | 30 | ||
| 30 | protected TokenChecker(JarFile jarFile) | 31 | protected TokenChecker(Path path) throws IOException { |
| 31 | throws IOException { | 32 | ClassCache classCache = ClassCache.of(path); |
| 32 | deobfuscator = new Deobfuscator(jarFile); | 33 | |
| 34 | CompiledSourceTypeLoader typeLoader = new CompiledSourceTypeLoader(classCache); | ||
| 35 | sourceProvider = new SourceProvider(SourceProvider.createSettings(), typeLoader); | ||
| 33 | } | 36 | } |
| 34 | 37 | ||
| 35 | protected String getDeclarationToken(Entry<?> entry) { | 38 | protected String getDeclarationToken(Entry<?> entry) { |
| 36 | // decompile the class | 39 | // decompile the class |
| 37 | SourceProvider sourceProvider = deobfuscator.getObfSourceProvider(); | ||
| 38 | CompilationUnit tree = sourceProvider.getSources(entry.getContainingClass().getFullName()); | 40 | CompilationUnit tree = sourceProvider.getSources(entry.getContainingClass().getFullName()); |
| 39 | // DEBUG | 41 | // DEBUG |
| 40 | // tree.acceptVisitor( new TreeDumpVisitor( new File( "tree." + entry.getClassName().replace( '/', '.' ) + ".txt" ) ), null ); | 42 | // tree.acceptVisitor( new TreeDumpVisitor( new File( "tree." + entry.getClassName().replace( '/', '.' ) + ".txt" ) ), null ); |
| @@ -52,7 +54,6 @@ public class TokenChecker { | |||
| 52 | @SuppressWarnings("unchecked") | 54 | @SuppressWarnings("unchecked") |
| 53 | protected Collection<String> getReferenceTokens(EntryReference<? extends Entry<?>, ? extends Entry<?>> reference) { | 55 | protected Collection<String> getReferenceTokens(EntryReference<? extends Entry<?>, ? extends Entry<?>> reference) { |
| 54 | // decompile the class | 56 | // decompile the class |
| 55 | SourceProvider sourceProvider = deobfuscator.getObfSourceProvider(); | ||
| 56 | CompilationUnit tree = sourceProvider.getSources(reference.context.getContainingClass().getFullName()); | 57 | CompilationUnit tree = sourceProvider.getSources(reference.context.getContainingClass().getFullName()); |
| 57 | String source = sourceProvider.writeSourceToString(tree); | 58 | String source = sourceProvider.writeSourceToString(tree); |
| 58 | SourceIndex index = SourceIndex.buildIndex(source, tree, true); | 59 | SourceIndex index = SourceIndex.buildIndex(source, tree, true); |