diff options
Diffstat (limited to 'src/test/java/cuchaz/enigma')
| -rw-r--r-- | src/test/java/cuchaz/enigma/TestDeobfed.java | 51 | ||||
| -rw-r--r-- | src/test/java/cuchaz/enigma/TestDeobfuscator.java | 10 | ||||
| -rw-r--r-- | src/test/java/cuchaz/enigma/TestInnerClasses.java | 13 | ||||
| -rw-r--r-- | src/test/java/cuchaz/enigma/TestSourceIndex.java | 12 | ||||
| -rw-r--r-- | src/test/java/cuchaz/enigma/TokenChecker.java | 27 |
5 files changed, 54 insertions, 59 deletions
diff --git a/src/test/java/cuchaz/enigma/TestDeobfed.java b/src/test/java/cuchaz/enigma/TestDeobfed.java index 3ee86cb..c88b0eb 100644 --- a/src/test/java/cuchaz/enigma/TestDeobfed.java +++ b/src/test/java/cuchaz/enigma/TestDeobfed.java | |||
| @@ -13,6 +13,9 @@ package cuchaz.enigma; | |||
| 13 | 13 | ||
| 14 | import cuchaz.enigma.analysis.ClassCache; | 14 | import cuchaz.enigma.analysis.ClassCache; |
| 15 | import cuchaz.enigma.analysis.index.JarIndex; | 15 | import cuchaz.enigma.analysis.index.JarIndex; |
| 16 | import cuchaz.enigma.source.Decompiler; | ||
| 17 | import cuchaz.enigma.source.Decompilers; | ||
| 18 | import cuchaz.enigma.source.SourceSettings; | ||
| 16 | import org.junit.BeforeClass; | 19 | import org.junit.BeforeClass; |
| 17 | import org.junit.Test; | 20 | import org.junit.Test; |
| 18 | 21 | ||
| @@ -68,31 +71,29 @@ public class TestDeobfed { | |||
| 68 | @Test | 71 | @Test |
| 69 | public void decompile() { | 72 | public void decompile() { |
| 70 | EnigmaProject project = new EnigmaProject(enigma, classCache, index); | 73 | EnigmaProject project = new EnigmaProject(enigma, classCache, index); |
| 74 | Decompiler decompiler = Decompilers.PROCYON.create(project.getClassCache(), new SourceSettings(false, false)); | ||
| 71 | 75 | ||
| 72 | CompiledSourceTypeLoader typeLoader = new CompiledSourceTypeLoader(project.getClassCache()); | 76 | decompiler.getSource("a"); |
| 73 | SourceProvider sourceProvider = new SourceProvider(SourceProvider.createSettings(), typeLoader); | 77 | decompiler.getSource("b"); |
| 74 | 78 | decompiler.getSource("c"); | |
| 75 | sourceProvider.getSources("a"); | 79 | decompiler.getSource("d"); |
| 76 | sourceProvider.getSources("b"); | 80 | decompiler.getSource("d$1"); |
| 77 | sourceProvider.getSources("c"); | 81 | decompiler.getSource("e"); |
| 78 | sourceProvider.getSources("d"); | 82 | decompiler.getSource("f"); |
| 79 | sourceProvider.getSources("d$1"); | 83 | decompiler.getSource("g"); |
| 80 | sourceProvider.getSources("e"); | 84 | decompiler.getSource("g$a"); |
| 81 | sourceProvider.getSources("f"); | 85 | decompiler.getSource("g$a$a"); |
| 82 | sourceProvider.getSources("g"); | 86 | decompiler.getSource("g$b"); |
| 83 | sourceProvider.getSources("g$a"); | 87 | decompiler.getSource("g$b$a"); |
| 84 | sourceProvider.getSources("g$a$a"); | 88 | decompiler.getSource("h"); |
| 85 | sourceProvider.getSources("g$b"); | 89 | decompiler.getSource("h$a"); |
| 86 | sourceProvider.getSources("g$b$a"); | 90 | decompiler.getSource("h$a$a"); |
| 87 | sourceProvider.getSources("h"); | 91 | decompiler.getSource("h$b"); |
| 88 | sourceProvider.getSources("h$a"); | 92 | decompiler.getSource("h$b$a"); |
| 89 | sourceProvider.getSources("h$a$a"); | 93 | decompiler.getSource("h$b$a$a"); |
| 90 | sourceProvider.getSources("h$b"); | 94 | decompiler.getSource("h$b$a$b"); |
| 91 | sourceProvider.getSources("h$b$a"); | 95 | decompiler.getSource("i"); |
| 92 | sourceProvider.getSources("h$b$a$a"); | 96 | decompiler.getSource("i$a"); |
| 93 | sourceProvider.getSources("h$b$a$b"); | 97 | decompiler.getSource("i$b"); |
| 94 | sourceProvider.getSources("i"); | ||
| 95 | sourceProvider.getSources("i$a"); | ||
| 96 | sourceProvider.getSources("i$b"); | ||
| 97 | } | 98 | } |
| 98 | } | 99 | } |
diff --git a/src/test/java/cuchaz/enigma/TestDeobfuscator.java b/src/test/java/cuchaz/enigma/TestDeobfuscator.java index 2a6fec4..6619d26 100644 --- a/src/test/java/cuchaz/enigma/TestDeobfuscator.java +++ b/src/test/java/cuchaz/enigma/TestDeobfuscator.java | |||
| @@ -11,13 +11,15 @@ | |||
| 11 | 11 | ||
| 12 | package cuchaz.enigma; | 12 | package cuchaz.enigma; |
| 13 | 13 | ||
| 14 | import cuchaz.enigma.source.Decompiler; | ||
| 15 | import cuchaz.enigma.source.Decompilers; | ||
| 16 | import cuchaz.enigma.source.SourceSettings; | ||
| 14 | import org.junit.Test; | 17 | import org.junit.Test; |
| 15 | 18 | ||
| 16 | import java.io.IOException; | 19 | import java.io.IOException; |
| 17 | import java.nio.file.Paths; | 20 | import java.nio.file.Paths; |
| 18 | 21 | ||
| 19 | public class TestDeobfuscator { | 22 | public class TestDeobfuscator { |
| 20 | |||
| 21 | private EnigmaProject openProject() throws IOException { | 23 | private EnigmaProject openProject() throws IOException { |
| 22 | Enigma enigma = Enigma.create(); | 24 | Enigma enigma = Enigma.create(); |
| 23 | return enigma.openJar(Paths.get("build/test-obf/loneClass.jar"), ProgressListener.none()); | 25 | return enigma.openJar(Paths.get("build/test-obf/loneClass.jar"), ProgressListener.none()); |
| @@ -32,10 +34,8 @@ public class TestDeobfuscator { | |||
| 32 | @Test | 34 | @Test |
| 33 | public void decompileClass() throws Exception { | 35 | public void decompileClass() throws Exception { |
| 34 | EnigmaProject project = openProject(); | 36 | EnigmaProject project = openProject(); |
| 37 | Decompiler decompiler = Decompilers.PROCYON.create(project.getClassCache(), new SourceSettings(false, false)); | ||
| 35 | 38 | ||
| 36 | CompiledSourceTypeLoader typeLoader = new CompiledSourceTypeLoader(project.getClassCache()); | 39 | decompiler.getSource("a").asString(); |
| 37 | SourceProvider sourceProvider = new SourceProvider(SourceProvider.createSettings(), typeLoader); | ||
| 38 | |||
| 39 | sourceProvider.writeSourceToString(sourceProvider.getSources("a")); | ||
| 40 | } | 40 | } |
| 41 | } | 41 | } |
diff --git a/src/test/java/cuchaz/enigma/TestInnerClasses.java b/src/test/java/cuchaz/enigma/TestInnerClasses.java index 18e4936..85c72f8 100644 --- a/src/test/java/cuchaz/enigma/TestInnerClasses.java +++ b/src/test/java/cuchaz/enigma/TestInnerClasses.java | |||
| @@ -13,6 +13,9 @@ package cuchaz.enigma; | |||
| 13 | 13 | ||
| 14 | import cuchaz.enigma.analysis.ClassCache; | 14 | import cuchaz.enigma.analysis.ClassCache; |
| 15 | import cuchaz.enigma.analysis.index.JarIndex; | 15 | import cuchaz.enigma.analysis.index.JarIndex; |
| 16 | import cuchaz.enigma.source.Decompiler; | ||
| 17 | import cuchaz.enigma.source.Decompilers; | ||
| 18 | import cuchaz.enigma.source.SourceSettings; | ||
| 16 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | 19 | import cuchaz.enigma.translation.representation.entry.ClassEntry; |
| 17 | import org.junit.Test; | 20 | import org.junit.Test; |
| 18 | 21 | ||
| @@ -32,15 +35,13 @@ public class TestInnerClasses { | |||
| 32 | private static final ClassEntry ClassTreeLevel1 = newClass("f$a"); | 35 | private static final ClassEntry ClassTreeLevel1 = newClass("f$a"); |
| 33 | private static final ClassEntry ClassTreeLevel2 = newClass("f$a$a"); | 36 | private static final ClassEntry ClassTreeLevel2 = newClass("f$a$a"); |
| 34 | private static final ClassEntry ClassTreeLevel3 = newClass("f$a$a$a"); | 37 | private static final ClassEntry ClassTreeLevel3 = newClass("f$a$a$a"); |
| 35 | private JarIndex index; | 38 | private final JarIndex index; |
| 36 | private SourceProvider sourceProvider; | 39 | private final Decompiler decompiler; |
| 37 | 40 | ||
| 38 | public TestInnerClasses() throws Exception { | 41 | public TestInnerClasses() throws Exception { |
| 39 | ClassCache classCache = ClassCache.of(Paths.get("build/test-obf/innerClasses.jar")); | 42 | ClassCache classCache = ClassCache.of(Paths.get("build/test-obf/innerClasses.jar")); |
| 40 | index = classCache.index(ProgressListener.none()); | 43 | index = classCache.index(ProgressListener.none()); |
| 41 | 44 | decompiler = Decompilers.PROCYON.create(classCache, new SourceSettings(false, false)); | |
| 42 | CompiledSourceTypeLoader typeLoader = new CompiledSourceTypeLoader(classCache); | ||
| 43 | sourceProvider = new SourceProvider(SourceProvider.createSettings(), typeLoader); | ||
| 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 | sourceProvider.getSources(classEntry.getName()); | 83 | decompiler.getSource(classEntry.getName()); |
| 83 | } | 84 | } |
| 84 | } | 85 | } |
diff --git a/src/test/java/cuchaz/enigma/TestSourceIndex.java b/src/test/java/cuchaz/enigma/TestSourceIndex.java index b1d1182..b201608 100644 --- a/src/test/java/cuchaz/enigma/TestSourceIndex.java +++ b/src/test/java/cuchaz/enigma/TestSourceIndex.java | |||
| @@ -12,9 +12,8 @@ | |||
| 12 | package cuchaz.enigma; | 12 | 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; | ||
| 16 | import cuchaz.enigma.analysis.ClassCache; | 15 | import cuchaz.enigma.analysis.ClassCache; |
| 17 | import cuchaz.enigma.analysis.SourceIndex; | 16 | import cuchaz.enigma.source.*; |
| 18 | import cuchaz.enigma.analysis.index.JarIndex; | 17 | import cuchaz.enigma.analysis.index.JarIndex; |
| 19 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | 18 | import cuchaz.enigma.translation.representation.entry.ClassEntry; |
| 20 | import org.junit.Test; | 19 | import org.junit.Test; |
| @@ -53,8 +52,7 @@ public class TestSourceIndex { | |||
| 53 | ClassCache classCache = project.getClassCache(); | 52 | ClassCache classCache = project.getClassCache(); |
| 54 | JarIndex index = project.getJarIndex(); | 53 | JarIndex index = project.getJarIndex(); |
| 55 | 54 | ||
| 56 | CompiledSourceTypeLoader typeLoader = new CompiledSourceTypeLoader(classCache); | 55 | Decompiler decompiler = Decompilers.PROCYON.create(classCache, new SourceSettings(false, false)); |
| 57 | SourceProvider sourceProvider = new SourceProvider(SourceProvider.createSettings(), typeLoader); | ||
| 58 | 56 | ||
| 59 | // get all classes that aren't inner classes | 57 | // get all classes that aren't inner classes |
| 60 | Set<ClassEntry> classEntries = Sets.newHashSet(); | 58 | Set<ClassEntry> classEntries = Sets.newHashSet(); |
| @@ -66,10 +64,8 @@ public class TestSourceIndex { | |||
| 66 | 64 | ||
| 67 | for (ClassEntry obfClassEntry : classEntries) { | 65 | for (ClassEntry obfClassEntry : classEntries) { |
| 68 | try { | 66 | try { |
| 69 | CompilationUnit tree = sourceProvider.getSources(obfClassEntry.getName()); | 67 | Source source = decompiler.getSource(obfClassEntry.getName()); |
| 70 | String source = sourceProvider.writeSourceToString(tree); | 68 | source.index(); |
| 71 | |||
| 72 | SourceIndex.buildIndex(source, tree, true); | ||
| 73 | } catch (Throwable t) { | 69 | } catch (Throwable t) { |
| 74 | throw new Error("Unable to index " + obfClassEntry, t); | 70 | throw new Error("Unable to index " + obfClassEntry, t); |
| 75 | } | 71 | } |
diff --git a/src/test/java/cuchaz/enigma/TokenChecker.java b/src/test/java/cuchaz/enigma/TokenChecker.java index 1dde034..48d0c83 100644 --- a/src/test/java/cuchaz/enigma/TokenChecker.java +++ b/src/test/java/cuchaz/enigma/TokenChecker.java | |||
| @@ -12,10 +12,10 @@ | |||
| 12 | package cuchaz.enigma; | 12 | 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; | ||
| 16 | import cuchaz.enigma.analysis.ClassCache; | 15 | import cuchaz.enigma.analysis.ClassCache; |
| 17 | import cuchaz.enigma.analysis.EntryReference; | 16 | import cuchaz.enigma.analysis.EntryReference; |
| 18 | import cuchaz.enigma.analysis.SourceIndex; | 17 | import cuchaz.enigma.source.SourceIndex; |
| 18 | import cuchaz.enigma.source.*; | ||
| 19 | import cuchaz.enigma.analysis.Token; | 19 | import cuchaz.enigma.analysis.Token; |
| 20 | import cuchaz.enigma.translation.representation.entry.Entry; | 20 | import cuchaz.enigma.translation.representation.entry.Entry; |
| 21 | 21 | ||
| @@ -25,43 +25,40 @@ import java.util.Collection; | |||
| 25 | import java.util.List; | 25 | import java.util.List; |
| 26 | 26 | ||
| 27 | public class TokenChecker { | 27 | public class TokenChecker { |
| 28 | 28 | private final Decompiler decompiler; | |
| 29 | private SourceProvider sourceProvider; | ||
| 30 | 29 | ||
| 31 | protected TokenChecker(Path path) throws IOException { | 30 | protected TokenChecker(Path path) throws IOException { |
| 32 | ClassCache classCache = ClassCache.of(path); | 31 | ClassCache classCache = ClassCache.of(path); |
| 33 | 32 | decompiler = Decompilers.PROCYON.create(classCache, new SourceSettings(false, false)); | |
| 34 | CompiledSourceTypeLoader typeLoader = new CompiledSourceTypeLoader(classCache); | ||
| 35 | sourceProvider = new SourceProvider(SourceProvider.createSettings(), typeLoader); | ||
| 36 | } | 33 | } |
| 37 | 34 | ||
| 38 | protected String getDeclarationToken(Entry<?> entry) { | 35 | protected String getDeclarationToken(Entry<?> entry) { |
| 39 | // decompile the class | 36 | // decompile the class |
| 40 | CompilationUnit tree = sourceProvider.getSources(entry.getContainingClass().getFullName()); | 37 | Source source = decompiler.getSource(entry.getContainingClass().getFullName()); |
| 41 | // DEBUG | 38 | // DEBUG |
| 42 | // tree.acceptVisitor( new TreeDumpVisitor( new File( "tree." + entry.getClassName().replace( '/', '.' ) + ".txt" ) ), null ); | 39 | // tree.acceptVisitor( new TreeDumpVisitor( new File( "tree." + entry.getClassName().replace( '/', '.' ) + ".txt" ) ), null ); |
| 43 | String source = sourceProvider.writeSourceToString(tree); | 40 | String string = source.asString(); |
| 44 | SourceIndex index = SourceIndex.buildIndex(source, tree, true); | 41 | SourceIndex index = source.index(); |
| 45 | 42 | ||
| 46 | // get the token value | 43 | // get the token value |
| 47 | Token token = index.getDeclarationToken(entry); | 44 | Token token = index.getDeclarationToken(entry); |
| 48 | if (token == null) { | 45 | if (token == null) { |
| 49 | return null; | 46 | return null; |
| 50 | } | 47 | } |
| 51 | return source.substring(token.start, token.end); | 48 | return string.substring(token.start, token.end); |
| 52 | } | 49 | } |
| 53 | 50 | ||
| 54 | @SuppressWarnings("unchecked") | 51 | @SuppressWarnings("unchecked") |
| 55 | protected Collection<String> getReferenceTokens(EntryReference<? extends Entry<?>, ? extends Entry<?>> reference) { | 52 | protected Collection<String> getReferenceTokens(EntryReference<? extends Entry<?>, ? extends Entry<?>> reference) { |
| 56 | // decompile the class | 53 | // decompile the class |
| 57 | CompilationUnit tree = sourceProvider.getSources(reference.context.getContainingClass().getFullName()); | 54 | Source source = decompiler.getSource(reference.context.getContainingClass().getFullName()); |
| 58 | String source = sourceProvider.writeSourceToString(tree); | 55 | String string = source.asString(); |
| 59 | SourceIndex index = SourceIndex.buildIndex(source, tree, true); | 56 | SourceIndex index = source.index(); |
| 60 | 57 | ||
| 61 | // get the token values | 58 | // get the token values |
| 62 | List<String> values = Lists.newArrayList(); | 59 | List<String> values = Lists.newArrayList(); |
| 63 | for (Token token : index.getReferenceTokens((EntryReference<Entry<?>, Entry<?>>) reference)) { | 60 | for (Token token : index.getReferenceTokens((EntryReference<Entry<?>, Entry<?>>) reference)) { |
| 64 | values.add(source.substring(token.start, token.end)); | 61 | values.add(string.substring(token.start, token.end)); |
| 65 | } | 62 | } |
| 66 | return values; | 63 | return values; |
| 67 | } | 64 | } |