diff options
| author | 2015-02-08 21:29:25 -0500 | |
|---|---|---|
| committer | 2015-02-08 21:29:25 -0500 | |
| commit | ed9b5cdfc648e86fd463bfa8d86b94c41671e14c (patch) | |
| tree | 2619bbc7e04dfa3b82f8dfd3b1d31f529766cd4b /test | |
| download | enigma-fork-ed9b5cdfc648e86fd463bfa8d86b94c41671e14c.tar.gz enigma-fork-ed9b5cdfc648e86fd463bfa8d86b94c41671e14c.tar.xz enigma-fork-ed9b5cdfc648e86fd463bfa8d86b94c41671e14c.zip | |
switch all classes to new signature/type system
Diffstat (limited to 'test')
30 files changed, 1818 insertions, 0 deletions
diff --git a/test/cuchaz/enigma/EntryFactory.java b/test/cuchaz/enigma/EntryFactory.java new file mode 100644 index 0000000..fa90779 --- /dev/null +++ b/test/cuchaz/enigma/EntryFactory.java | |||
| @@ -0,0 +1,67 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2014 Jeff Martin.\ | ||
| 3 | * | ||
| 4 | * All rights reserved. This program and the accompanying materials | ||
| 5 | * are made available under the terms of the GNU Public License v3.0 | ||
| 6 | * which accompanies this distribution, and is available at | ||
| 7 | * http://www.gnu.org/licenses/gpl.html | ||
| 8 | * | ||
| 9 | * Contributors: | ||
| 10 | * Jeff Martin - initial API and implementation | ||
| 11 | ******************************************************************************/ | ||
| 12 | package cuchaz.enigma; | ||
| 13 | |||
| 14 | import cuchaz.enigma.analysis.EntryReference; | ||
| 15 | import cuchaz.enigma.mapping.BehaviorEntry; | ||
| 16 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 17 | import cuchaz.enigma.mapping.ConstructorEntry; | ||
| 18 | import cuchaz.enigma.mapping.FieldEntry; | ||
| 19 | import cuchaz.enigma.mapping.MethodEntry; | ||
| 20 | import cuchaz.enigma.mapping.Signature; | ||
| 21 | |||
| 22 | public class EntryFactory { | ||
| 23 | |||
| 24 | public static ClassEntry newClass(String name) { | ||
| 25 | return new ClassEntry(name); | ||
| 26 | } | ||
| 27 | |||
| 28 | public static FieldEntry newField(String className, String fieldName) { | ||
| 29 | return newField(newClass(className), fieldName); | ||
| 30 | } | ||
| 31 | |||
| 32 | public static FieldEntry newField(ClassEntry classEntry, String fieldName) { | ||
| 33 | return new FieldEntry(classEntry, fieldName); | ||
| 34 | } | ||
| 35 | |||
| 36 | public static MethodEntry newMethod(String className, String methodName, String methodSignature) { | ||
| 37 | return newMethod(newClass(className), methodName, methodSignature); | ||
| 38 | } | ||
| 39 | |||
| 40 | public static MethodEntry newMethod(ClassEntry classEntry, String methodName, String methodSignature) { | ||
| 41 | return new MethodEntry(classEntry, methodName, new Signature(methodSignature)); | ||
| 42 | } | ||
| 43 | |||
| 44 | public static ConstructorEntry newConstructor(String className, String signature) { | ||
| 45 | return newConstructor(newClass(className), signature); | ||
| 46 | } | ||
| 47 | |||
| 48 | public static ConstructorEntry newConstructor(ClassEntry classEntry, String signature) { | ||
| 49 | return new ConstructorEntry(classEntry, new Signature(signature)); | ||
| 50 | } | ||
| 51 | |||
| 52 | public static EntryReference<FieldEntry,BehaviorEntry> newFieldReferenceByMethod(FieldEntry fieldEntry, String callerClassName, String callerName, String callerSignature) { | ||
| 53 | return new EntryReference<FieldEntry,BehaviorEntry>(fieldEntry, "", newMethod(callerClassName, callerName, callerSignature)); | ||
| 54 | } | ||
| 55 | |||
| 56 | public static EntryReference<FieldEntry,BehaviorEntry> newFieldReferenceByConstructor(FieldEntry fieldEntry, String callerClassName, String callerSignature) { | ||
| 57 | return new EntryReference<FieldEntry,BehaviorEntry>(fieldEntry, "", newConstructor(callerClassName, callerSignature)); | ||
| 58 | } | ||
| 59 | |||
| 60 | public static EntryReference<BehaviorEntry,BehaviorEntry> newBehaviorReferenceByMethod(BehaviorEntry behaviorEntry, String callerClassName, String callerName, String callerSignature) { | ||
| 61 | return new EntryReference<BehaviorEntry,BehaviorEntry>(behaviorEntry, "", newMethod(callerClassName, callerName, callerSignature)); | ||
| 62 | } | ||
| 63 | |||
| 64 | public static EntryReference<BehaviorEntry,BehaviorEntry> newBehaviorReferenceByConstructor(BehaviorEntry behaviorEntry, String callerClassName, String callerSignature) { | ||
| 65 | return new EntryReference<BehaviorEntry,BehaviorEntry>(behaviorEntry, "", newConstructor(callerClassName, callerSignature)); | ||
| 66 | } | ||
| 67 | } | ||
diff --git a/test/cuchaz/enigma/TestDeobfuscator.java b/test/cuchaz/enigma/TestDeobfuscator.java new file mode 100644 index 0000000..26d492d --- /dev/null +++ b/test/cuchaz/enigma/TestDeobfuscator.java | |||
| @@ -0,0 +1,58 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2014 Jeff Martin.\ | ||
| 3 | * | ||
| 4 | * All rights reserved. This program and the accompanying materials | ||
| 5 | * are made available under the terms of the GNU Public License v3.0 | ||
| 6 | * which accompanies this distribution, and is available at | ||
| 7 | * http://www.gnu.org/licenses/gpl.html | ||
| 8 | * | ||
| 9 | * Contributors: | ||
| 10 | * Jeff Martin - initial API and implementation | ||
| 11 | ******************************************************************************/ | ||
| 12 | package cuchaz.enigma; | ||
| 13 | |||
| 14 | import static org.junit.Assert.*; | ||
| 15 | |||
| 16 | import java.io.IOException; | ||
| 17 | import java.util.List; | ||
| 18 | import java.util.jar.JarFile; | ||
| 19 | |||
| 20 | import org.junit.Test; | ||
| 21 | |||
| 22 | import com.google.common.collect.Lists; | ||
| 23 | |||
| 24 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 25 | |||
| 26 | public class TestDeobfuscator { | ||
| 27 | |||
| 28 | private Deobfuscator getDeobfuscator() | ||
| 29 | throws IOException { | ||
| 30 | return new Deobfuscator(new JarFile("build/testLoneClass.obf.jar")); | ||
| 31 | } | ||
| 32 | |||
| 33 | @Test | ||
| 34 | public void loadJar() | ||
| 35 | throws Exception { | ||
| 36 | getDeobfuscator(); | ||
| 37 | } | ||
| 38 | |||
| 39 | @Test | ||
| 40 | public void getClasses() | ||
| 41 | throws Exception { | ||
| 42 | Deobfuscator deobfuscator = getDeobfuscator(); | ||
| 43 | List<ClassEntry> obfClasses = Lists.newArrayList(); | ||
| 44 | List<ClassEntry> deobfClasses = Lists.newArrayList(); | ||
| 45 | deobfuscator.getSeparatedClasses(obfClasses, deobfClasses); | ||
| 46 | assertEquals(1, obfClasses.size()); | ||
| 47 | assertEquals("none/a", obfClasses.get(0).getName()); | ||
| 48 | assertEquals(1, deobfClasses.size()); | ||
| 49 | assertEquals("cuchaz/enigma/inputs/Keep", deobfClasses.get(0).getName()); | ||
| 50 | } | ||
| 51 | |||
| 52 | @Test | ||
| 53 | public void decompileClass() | ||
| 54 | throws Exception { | ||
| 55 | Deobfuscator deobfuscator = getDeobfuscator(); | ||
| 56 | deobfuscator.getSource(deobfuscator.getSourceTree("none/a")); | ||
| 57 | } | ||
| 58 | } | ||
diff --git a/test/cuchaz/enigma/TestInnerClasses.java b/test/cuchaz/enigma/TestInnerClasses.java new file mode 100644 index 0000000..2e16a33 --- /dev/null +++ b/test/cuchaz/enigma/TestInnerClasses.java | |||
| @@ -0,0 +1,90 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2014 Jeff Martin. | ||
| 3 | * | ||
| 4 | * All rights reserved. This program and the accompanying materials | ||
| 5 | * are made available under the terms of the GNU Public License v3.0 | ||
| 6 | * which accompanies this distribution, and is available at | ||
| 7 | * http://www.gnu.org/licenses/gpl.html | ||
| 8 | * | ||
| 9 | * Contributors: | ||
| 10 | * Jeff Martin - initial API and implementation | ||
| 11 | ******************************************************************************/ | ||
| 12 | package cuchaz.enigma; | ||
| 13 | |||
| 14 | import static org.hamcrest.MatcherAssert.*; | ||
| 15 | import static org.hamcrest.Matchers.*; | ||
| 16 | |||
| 17 | import java.util.jar.JarFile; | ||
| 18 | |||
| 19 | import org.junit.Test; | ||
| 20 | |||
| 21 | import cuchaz.enigma.analysis.JarIndex; | ||
| 22 | |||
| 23 | public class TestInnerClasses { | ||
| 24 | |||
| 25 | private JarIndex m_index; | ||
| 26 | private Deobfuscator m_deobfuscator; | ||
| 27 | |||
| 28 | private static final String AnonymousOuter = "none/a"; | ||
| 29 | private static final String AnonymousInner = "b"; | ||
| 30 | private static final String SimpleOuter = "none/g"; | ||
| 31 | private static final String SimpleInner = "h"; | ||
| 32 | private static final String ConstructorArgsOuter = "none/e"; | ||
| 33 | private static final String ConstructorArgsInner = "f"; | ||
| 34 | private static final String AnonymousWithScopeArgsOuter = "none/c"; | ||
| 35 | private static final String AnonymousWithScopeArgsInner = "d"; | ||
| 36 | private static final String AnonymousWithOuterAccessOuter = "none/i"; | ||
| 37 | private static final String AnonymousWithOuterAccessInner = "j"; | ||
| 38 | |||
| 39 | public TestInnerClasses() | ||
| 40 | throws Exception { | ||
| 41 | m_index = new JarIndex(); | ||
| 42 | JarFile jar = new JarFile("build/testInnerClasses.obf.jar"); | ||
| 43 | m_index.indexJar(jar, true); | ||
| 44 | m_deobfuscator = new Deobfuscator(jar); | ||
| 45 | } | ||
| 46 | |||
| 47 | @Test | ||
| 48 | public void simple() { | ||
| 49 | assertThat(m_index.getOuterClass(SimpleInner), is(SimpleOuter)); | ||
| 50 | assertThat(m_index.getInnerClasses(SimpleOuter), containsInAnyOrder(SimpleInner)); | ||
| 51 | assertThat(m_index.isAnonymousClass(SimpleInner), is(false)); | ||
| 52 | decompile(SimpleOuter); | ||
| 53 | } | ||
| 54 | |||
| 55 | @Test | ||
| 56 | public void anonymous() { | ||
| 57 | assertThat(m_index.getOuterClass(AnonymousInner), is(AnonymousOuter)); | ||
| 58 | assertThat(m_index.getInnerClasses(AnonymousOuter), containsInAnyOrder(AnonymousInner)); | ||
| 59 | assertThat(m_index.isAnonymousClass(AnonymousInner), is(true)); | ||
| 60 | decompile(AnonymousOuter); | ||
| 61 | } | ||
| 62 | |||
| 63 | @Test | ||
| 64 | public void constructorArgs() { | ||
| 65 | assertThat(m_index.getOuterClass(ConstructorArgsInner), is(ConstructorArgsOuter)); | ||
| 66 | assertThat(m_index.getInnerClasses(ConstructorArgsOuter), containsInAnyOrder(ConstructorArgsInner)); | ||
| 67 | assertThat(m_index.isAnonymousClass(ConstructorArgsInner), is(false)); | ||
| 68 | decompile(ConstructorArgsOuter); | ||
| 69 | } | ||
| 70 | |||
| 71 | @Test | ||
| 72 | public void anonymousWithScopeArgs() { | ||
| 73 | assertThat(m_index.getOuterClass(AnonymousWithScopeArgsInner), is(AnonymousWithScopeArgsOuter)); | ||
| 74 | assertThat(m_index.getInnerClasses(AnonymousWithScopeArgsOuter), containsInAnyOrder(AnonymousWithScopeArgsInner)); | ||
| 75 | assertThat(m_index.isAnonymousClass(AnonymousWithScopeArgsInner), is(true)); | ||
| 76 | decompile(AnonymousWithScopeArgsOuter); | ||
| 77 | } | ||
| 78 | |||
| 79 | @Test | ||
| 80 | public void anonymousWithOuterAccess() { | ||
| 81 | assertThat(m_index.getOuterClass(AnonymousWithOuterAccessInner), is(AnonymousWithOuterAccessOuter)); | ||
| 82 | assertThat(m_index.getInnerClasses(AnonymousWithOuterAccessOuter), containsInAnyOrder(AnonymousWithOuterAccessInner)); | ||
| 83 | assertThat(m_index.isAnonymousClass(AnonymousWithOuterAccessInner), is(true)); | ||
| 84 | decompile(AnonymousWithOuterAccessOuter); | ||
| 85 | } | ||
| 86 | |||
| 87 | private void decompile(String name) { | ||
| 88 | m_deobfuscator.getSourceTree(name); | ||
| 89 | } | ||
| 90 | } | ||
diff --git a/test/cuchaz/enigma/TestJarIndexConstructorReferences.java b/test/cuchaz/enigma/TestJarIndexConstructorReferences.java new file mode 100644 index 0000000..22812fe --- /dev/null +++ b/test/cuchaz/enigma/TestJarIndexConstructorReferences.java | |||
| @@ -0,0 +1,124 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2014 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Public License v3.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/gpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma; | ||
| 12 | |||
| 13 | import static cuchaz.enigma.EntryFactory.*; | ||
| 14 | import static org.hamcrest.MatcherAssert.*; | ||
| 15 | import static org.hamcrest.Matchers.*; | ||
| 16 | |||
| 17 | import java.io.File; | ||
| 18 | import java.util.Collection; | ||
| 19 | import java.util.jar.JarFile; | ||
| 20 | |||
| 21 | import org.junit.Test; | ||
| 22 | |||
| 23 | import cuchaz.enigma.analysis.EntryReference; | ||
| 24 | import cuchaz.enigma.analysis.JarIndex; | ||
| 25 | import cuchaz.enigma.mapping.BehaviorEntry; | ||
| 26 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 27 | |||
| 28 | public class TestJarIndexConstructorReferences { | ||
| 29 | |||
| 30 | private JarIndex m_index; | ||
| 31 | |||
| 32 | private ClassEntry m_baseClass = newClass("none/a"); | ||
| 33 | private ClassEntry m_subClass = newClass("none/d"); | ||
| 34 | private ClassEntry m_subsubClass = newClass("none/e"); | ||
| 35 | private ClassEntry m_defaultClass = newClass("none/c"); | ||
| 36 | private ClassEntry m_callerClass = newClass("none/b"); | ||
| 37 | |||
| 38 | public TestJarIndexConstructorReferences() | ||
| 39 | throws Exception { | ||
| 40 | File jarFile = new File("build/testConstructors.obf.jar"); | ||
| 41 | m_index = new JarIndex(); | ||
| 42 | m_index.indexJar(new JarFile(jarFile), false); | ||
| 43 | } | ||
| 44 | |||
| 45 | @Test | ||
| 46 | public void obfEntries() { | ||
| 47 | assertThat(m_index.getObfClassEntries(), containsInAnyOrder(newClass("cuchaz/enigma/inputs/Keep"), m_baseClass, m_subClass, m_subsubClass, m_defaultClass, m_callerClass)); | ||
| 48 | } | ||
| 49 | |||
| 50 | @Test | ||
| 51 | @SuppressWarnings("unchecked") | ||
| 52 | public void baseDefault() { | ||
| 53 | BehaviorEntry source = newConstructor(m_baseClass, "()V"); | ||
| 54 | Collection<EntryReference<BehaviorEntry,BehaviorEntry>> references = m_index.getBehaviorReferences(source); | ||
| 55 | assertThat(references, containsInAnyOrder( | ||
| 56 | newBehaviorReferenceByMethod(source, m_callerClass.getName(), "a", "()V"), | ||
| 57 | newBehaviorReferenceByConstructor(source, m_subClass.getName(), "()V"), | ||
| 58 | newBehaviorReferenceByConstructor(source, m_subClass.getName(), "(III)V") | ||
| 59 | )); | ||
| 60 | } | ||
| 61 | |||
| 62 | @Test | ||
| 63 | @SuppressWarnings("unchecked") | ||
| 64 | public void baseInt() { | ||
| 65 | BehaviorEntry source = newConstructor(m_baseClass, "(I)V"); | ||
| 66 | assertThat(m_index.getBehaviorReferences(source), containsInAnyOrder( | ||
| 67 | newBehaviorReferenceByMethod(source, m_callerClass.getName(), "b", "()V") | ||
| 68 | )); | ||
| 69 | } | ||
| 70 | |||
| 71 | @Test | ||
| 72 | @SuppressWarnings("unchecked") | ||
| 73 | public void subDefault() { | ||
| 74 | BehaviorEntry source = newConstructor(m_subClass, "()V"); | ||
| 75 | assertThat(m_index.getBehaviorReferences(source), containsInAnyOrder( | ||
| 76 | newBehaviorReferenceByMethod(source, m_callerClass.getName(), "c", "()V"), | ||
| 77 | newBehaviorReferenceByConstructor(source, m_subClass.getName(), "(I)V") | ||
| 78 | )); | ||
| 79 | } | ||
| 80 | |||
| 81 | @Test | ||
| 82 | @SuppressWarnings("unchecked") | ||
| 83 | public void subInt() { | ||
| 84 | BehaviorEntry source = newConstructor(m_subClass, "(I)V"); | ||
| 85 | assertThat(m_index.getBehaviorReferences(source), containsInAnyOrder( | ||
| 86 | newBehaviorReferenceByMethod(source, m_callerClass.getName(), "d", "()V"), | ||
| 87 | newBehaviorReferenceByConstructor(source, m_subClass.getName(), "(II)V"), | ||
| 88 | newBehaviorReferenceByConstructor(source, m_subsubClass.getName(), "(I)V") | ||
| 89 | )); | ||
| 90 | } | ||
| 91 | |||
| 92 | @Test | ||
| 93 | @SuppressWarnings("unchecked") | ||
| 94 | public void subIntInt() { | ||
| 95 | BehaviorEntry source = newConstructor(m_subClass, "(II)V"); | ||
| 96 | assertThat(m_index.getBehaviorReferences(source), containsInAnyOrder( | ||
| 97 | newBehaviorReferenceByMethod(source, m_callerClass.getName(), "e", "()V") | ||
| 98 | )); | ||
| 99 | } | ||
| 100 | |||
| 101 | @Test | ||
| 102 | public void subIntIntInt() { | ||
| 103 | BehaviorEntry source = newConstructor(m_subClass, "(III)V"); | ||
| 104 | assertThat(m_index.getBehaviorReferences(source), is(empty())); | ||
| 105 | } | ||
| 106 | |||
| 107 | @Test | ||
| 108 | @SuppressWarnings("unchecked") | ||
| 109 | public void subsubInt() { | ||
| 110 | BehaviorEntry source = newConstructor(m_subsubClass, "(I)V"); | ||
| 111 | assertThat(m_index.getBehaviorReferences(source), containsInAnyOrder( | ||
| 112 | newBehaviorReferenceByMethod(source, m_callerClass.getName(), "f", "()V") | ||
| 113 | )); | ||
| 114 | } | ||
| 115 | |||
| 116 | @Test | ||
| 117 | @SuppressWarnings("unchecked") | ||
| 118 | public void defaultConstructable() { | ||
| 119 | BehaviorEntry source = newConstructor(m_defaultClass, "()V"); | ||
| 120 | assertThat(m_index.getBehaviorReferences(source), containsInAnyOrder( | ||
| 121 | newBehaviorReferenceByMethod(source, m_callerClass.getName(), "g", "()V") | ||
| 122 | )); | ||
| 123 | } | ||
| 124 | } | ||
diff --git a/test/cuchaz/enigma/TestJarIndexInheritanceTree.java b/test/cuchaz/enigma/TestJarIndexInheritanceTree.java new file mode 100644 index 0000000..1d6e5a5 --- /dev/null +++ b/test/cuchaz/enigma/TestJarIndexInheritanceTree.java | |||
| @@ -0,0 +1,228 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2014 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Public License v3.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/gpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma; | ||
| 12 | |||
| 13 | import static cuchaz.enigma.EntryFactory.*; | ||
| 14 | import static org.hamcrest.MatcherAssert.*; | ||
| 15 | import static org.hamcrest.Matchers.*; | ||
| 16 | |||
| 17 | import java.util.Collection; | ||
| 18 | import java.util.Set; | ||
| 19 | import java.util.jar.JarFile; | ||
| 20 | |||
| 21 | import org.junit.Test; | ||
| 22 | |||
| 23 | import cuchaz.enigma.analysis.Access; | ||
| 24 | import cuchaz.enigma.analysis.EntryReference; | ||
| 25 | import cuchaz.enigma.analysis.JarIndex; | ||
| 26 | import cuchaz.enigma.analysis.TranslationIndex; | ||
| 27 | import cuchaz.enigma.mapping.BehaviorEntry; | ||
| 28 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 29 | import cuchaz.enigma.mapping.FieldEntry; | ||
| 30 | import cuchaz.enigma.mapping.MethodEntry; | ||
| 31 | |||
| 32 | public class TestJarIndexInheritanceTree { | ||
| 33 | |||
| 34 | private JarIndex m_index; | ||
| 35 | |||
| 36 | private ClassEntry m_baseClass = newClass("none/a"); | ||
| 37 | private ClassEntry m_subClassA = newClass("none/b"); | ||
| 38 | private ClassEntry m_subClassAA = newClass("none/d"); | ||
| 39 | private ClassEntry m_subClassB = newClass("none/c"); | ||
| 40 | private FieldEntry m_nameField = new FieldEntry(m_baseClass, "a"); | ||
| 41 | private FieldEntry m_numThingsField = new FieldEntry(m_subClassB, "a"); | ||
| 42 | |||
| 43 | public TestJarIndexInheritanceTree() | ||
| 44 | throws Exception { | ||
| 45 | m_index = new JarIndex(); | ||
| 46 | m_index.indexJar(new JarFile("build/testInheritanceTree.obf.jar"), false); | ||
| 47 | } | ||
| 48 | |||
| 49 | @Test | ||
| 50 | public void obfEntries() { | ||
| 51 | assertThat(m_index.getObfClassEntries(), containsInAnyOrder( | ||
| 52 | newClass("cuchaz/enigma/inputs/Keep"), | ||
| 53 | m_baseClass, | ||
| 54 | m_subClassA, | ||
| 55 | m_subClassAA, | ||
| 56 | m_subClassB | ||
| 57 | )); | ||
| 58 | } | ||
| 59 | |||
| 60 | @Test | ||
| 61 | public void translationIndex() { | ||
| 62 | |||
| 63 | TranslationIndex index = m_index.getTranslationIndex(); | ||
| 64 | |||
| 65 | // base class | ||
| 66 | assertThat(index.getSuperclass(m_baseClass), is(nullValue())); | ||
| 67 | assertThat(index.getAncestry(m_baseClass), is(empty())); | ||
| 68 | assertThat(index.getSubclass(m_baseClass), containsInAnyOrder( | ||
| 69 | m_subClassA, | ||
| 70 | m_subClassB | ||
| 71 | )); | ||
| 72 | |||
| 73 | // subclass a | ||
| 74 | assertThat(index.getSuperclass(m_subClassA), is(m_baseClass)); | ||
| 75 | assertThat(index.getAncestry(m_subClassA), contains(m_baseClass)); | ||
| 76 | assertThat(index.getSubclass(m_subClassA), contains(m_subClassAA)); | ||
| 77 | |||
| 78 | // subclass aa | ||
| 79 | assertThat(index.getSuperclass(m_subClassAA), is(m_subClassA)); | ||
| 80 | assertThat(index.getAncestry(m_subClassAA), contains(m_subClassA, m_baseClass)); | ||
| 81 | assertThat(index.getSubclass(m_subClassAA), is(empty())); | ||
| 82 | |||
| 83 | // subclass b | ||
| 84 | assertThat(index.getSuperclass(m_subClassB), is(m_baseClass)); | ||
| 85 | assertThat(index.getAncestry(m_subClassB), contains(m_baseClass)); | ||
| 86 | assertThat(index.getSubclass(m_subClassB), is(empty())); | ||
| 87 | } | ||
| 88 | |||
| 89 | @Test | ||
| 90 | public void access() { | ||
| 91 | assertThat(m_index.getAccess(m_nameField), is(Access.Private)); | ||
| 92 | assertThat(m_index.getAccess(m_numThingsField), is(Access.Private)); | ||
| 93 | } | ||
| 94 | |||
| 95 | @Test | ||
| 96 | public void relatedMethodImplementations() { | ||
| 97 | |||
| 98 | Set<MethodEntry> entries; | ||
| 99 | |||
| 100 | // getName() | ||
| 101 | entries = m_index.getRelatedMethodImplementations(newMethod(m_baseClass, "a", "()Ljava/lang/String;")); | ||
| 102 | assertThat(entries, containsInAnyOrder( | ||
| 103 | newMethod(m_baseClass, "a", "()Ljava/lang/String;"), | ||
| 104 | newMethod(m_subClassAA, "a", "()Ljava/lang/String;") | ||
| 105 | )); | ||
| 106 | entries = m_index.getRelatedMethodImplementations(newMethod(m_subClassAA, "a", "()Ljava/lang/String;")); | ||
| 107 | assertThat(entries, containsInAnyOrder( | ||
| 108 | newMethod(m_baseClass, "a", "()Ljava/lang/String;"), | ||
| 109 | newMethod(m_subClassAA, "a", "()Ljava/lang/String;") | ||
| 110 | )); | ||
| 111 | |||
| 112 | // doBaseThings() | ||
| 113 | entries = m_index.getRelatedMethodImplementations(newMethod(m_baseClass, "a", "()V")); | ||
| 114 | assertThat(entries, containsInAnyOrder( | ||
| 115 | newMethod(m_baseClass, "a", "()V"), | ||
| 116 | newMethod(m_subClassAA, "a", "()V"), | ||
| 117 | newMethod(m_subClassB, "a", "()V") | ||
| 118 | )); | ||
| 119 | entries = m_index.getRelatedMethodImplementations(newMethod(m_subClassAA, "a", "()V")); | ||
| 120 | assertThat(entries, containsInAnyOrder( | ||
| 121 | newMethod(m_baseClass, "a", "()V"), | ||
| 122 | newMethod(m_subClassAA, "a", "()V"), | ||
| 123 | newMethod(m_subClassB, "a", "()V") | ||
| 124 | )); | ||
| 125 | entries = m_index.getRelatedMethodImplementations(newMethod(m_subClassB, "a", "()V")); | ||
| 126 | assertThat(entries, containsInAnyOrder( | ||
| 127 | newMethod(m_baseClass, "a", "()V"), | ||
| 128 | newMethod(m_subClassAA, "a", "()V"), | ||
| 129 | newMethod(m_subClassB, "a", "()V") | ||
| 130 | )); | ||
| 131 | |||
| 132 | // doBThings | ||
| 133 | entries = m_index.getRelatedMethodImplementations(newMethod(m_subClassB, "b", "()V")); | ||
| 134 | assertThat(entries, containsInAnyOrder(newMethod(m_subClassB, "b", "()V"))); | ||
| 135 | } | ||
| 136 | |||
| 137 | @Test | ||
| 138 | @SuppressWarnings("unchecked") | ||
| 139 | public void fieldReferences() { | ||
| 140 | Collection<EntryReference<FieldEntry,BehaviorEntry>> references; | ||
| 141 | |||
| 142 | // name | ||
| 143 | references = m_index.getFieldReferences(m_nameField); | ||
| 144 | assertThat(references, containsInAnyOrder( | ||
| 145 | newFieldReferenceByConstructor(m_nameField, m_baseClass.getName(), "(Ljava/lang/String;)V"), | ||
| 146 | newFieldReferenceByMethod(m_nameField, m_baseClass.getName(), "a", "()Ljava/lang/String;") | ||
| 147 | )); | ||
| 148 | |||
| 149 | // numThings | ||
| 150 | references = m_index.getFieldReferences(m_numThingsField); | ||
| 151 | assertThat(references, containsInAnyOrder( | ||
| 152 | newFieldReferenceByConstructor(m_numThingsField, m_subClassB.getName(), "()V"), | ||
| 153 | newFieldReferenceByMethod(m_numThingsField, m_subClassB.getName(), "b", "()V") | ||
| 154 | )); | ||
| 155 | } | ||
| 156 | |||
| 157 | @Test | ||
| 158 | @SuppressWarnings("unchecked") | ||
| 159 | public void behaviorReferences() { | ||
| 160 | |||
| 161 | BehaviorEntry source; | ||
| 162 | Collection<EntryReference<BehaviorEntry,BehaviorEntry>> references; | ||
| 163 | |||
| 164 | // baseClass constructor | ||
| 165 | source = newConstructor(m_baseClass, "(Ljava/lang/String;)V"); | ||
| 166 | references = m_index.getBehaviorReferences(source); | ||
| 167 | assertThat(references, containsInAnyOrder( | ||
| 168 | newBehaviorReferenceByConstructor(source, m_subClassA.getName(), "(Ljava/lang/String;)V"), | ||
| 169 | newBehaviorReferenceByConstructor(source, m_subClassB.getName(), "()V") | ||
| 170 | )); | ||
| 171 | |||
| 172 | // subClassA constructor | ||
| 173 | source = newConstructor(m_subClassA, "(Ljava/lang/String;)V"); | ||
| 174 | references = m_index.getBehaviorReferences(source); | ||
| 175 | assertThat(references, containsInAnyOrder( | ||
| 176 | newBehaviorReferenceByConstructor(source, m_subClassAA.getName(), "()V") | ||
| 177 | )); | ||
| 178 | |||
| 179 | // baseClass.getName() | ||
| 180 | source = newMethod(m_baseClass, "a", "()Ljava/lang/String;"); | ||
| 181 | references = m_index.getBehaviorReferences(source); | ||
| 182 | assertThat(references, containsInAnyOrder( | ||
| 183 | newBehaviorReferenceByMethod(source, m_subClassAA.getName(), "a", "()Ljava/lang/String;"), | ||
| 184 | newBehaviorReferenceByMethod(source, m_subClassB.getName(), "a", "()V") | ||
| 185 | )); | ||
| 186 | |||
| 187 | // subclassAA.getName() | ||
| 188 | source = newMethod(m_subClassAA, "a", "()Ljava/lang/String;"); | ||
| 189 | references = m_index.getBehaviorReferences(source); | ||
| 190 | assertThat(references, containsInAnyOrder( | ||
| 191 | newBehaviorReferenceByMethod(source, m_subClassAA.getName(), "a", "()V") | ||
| 192 | )); | ||
| 193 | } | ||
| 194 | |||
| 195 | @Test | ||
| 196 | public void containsEntries() { | ||
| 197 | |||
| 198 | // classes | ||
| 199 | assertThat(m_index.containsObfClass(m_baseClass), is(true)); | ||
| 200 | assertThat(m_index.containsObfClass(m_subClassA), is(true)); | ||
| 201 | assertThat(m_index.containsObfClass(m_subClassAA), is(true)); | ||
| 202 | assertThat(m_index.containsObfClass(m_subClassB), is(true)); | ||
| 203 | |||
| 204 | // fields | ||
| 205 | assertThat(m_index.containsObfField(m_nameField), is(true)); | ||
| 206 | assertThat(m_index.containsObfField(m_numThingsField), is(true)); | ||
| 207 | |||
| 208 | // methods | ||
| 209 | // getName() | ||
| 210 | assertThat(m_index.containsObfBehavior(newMethod(m_baseClass, "a", "()Ljava/lang/String;")), is(true)); | ||
| 211 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassA, "a", "()Ljava/lang/String;")), is(false)); | ||
| 212 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassAA, "a", "()Ljava/lang/String;")), is(true)); | ||
| 213 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassB, "a", "()Ljava/lang/String;")), is(false)); | ||
| 214 | |||
| 215 | // doBaseThings() | ||
| 216 | assertThat(m_index.containsObfBehavior(newMethod(m_baseClass, "a", "()V")), is(true)); | ||
| 217 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassA, "a", "()V")), is(false)); | ||
| 218 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassAA, "a", "()V")), is(true)); | ||
| 219 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassB, "a", "()V")), is(true)); | ||
| 220 | |||
| 221 | // doBThings() | ||
| 222 | assertThat(m_index.containsObfBehavior(newMethod(m_baseClass, "b", "()V")), is(false)); | ||
| 223 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassA, "b", "()V")), is(false)); | ||
| 224 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassAA, "b", "()V")), is(false)); | ||
| 225 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassB, "b", "()V")), is(true)); | ||
| 226 | |||
| 227 | } | ||
| 228 | } | ||
diff --git a/test/cuchaz/enigma/TestJarIndexLoneClass.java b/test/cuchaz/enigma/TestJarIndexLoneClass.java new file mode 100644 index 0000000..c6a9e55 --- /dev/null +++ b/test/cuchaz/enigma/TestJarIndexLoneClass.java | |||
| @@ -0,0 +1,165 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2014 Jeff Martin. | ||
| 3 | * | ||
| 4 | * All rights reserved. This program and the accompanying materials | ||
| 5 | * are made available under the terms of the GNU Public License v3.0 | ||
| 6 | * which accompanies this distribution, and is available at | ||
| 7 | * http://www.gnu.org/licenses/gpl.html | ||
| 8 | * | ||
| 9 | * Contributors: | ||
| 10 | * Jeff Martin - initial API and implementation | ||
| 11 | ******************************************************************************/ | ||
| 12 | package cuchaz.enigma; | ||
| 13 | |||
| 14 | import static cuchaz.enigma.EntryFactory.*; | ||
| 15 | import static org.hamcrest.MatcherAssert.*; | ||
| 16 | import static org.hamcrest.Matchers.*; | ||
| 17 | |||
| 18 | import java.util.Collection; | ||
| 19 | import java.util.Set; | ||
| 20 | import java.util.jar.JarFile; | ||
| 21 | |||
| 22 | import org.junit.Test; | ||
| 23 | |||
| 24 | import cuchaz.enigma.analysis.Access; | ||
| 25 | import cuchaz.enigma.analysis.ClassImplementationsTreeNode; | ||
| 26 | import cuchaz.enigma.analysis.ClassInheritanceTreeNode; | ||
| 27 | import cuchaz.enigma.analysis.EntryReference; | ||
| 28 | import cuchaz.enigma.analysis.JarIndex; | ||
| 29 | import cuchaz.enigma.analysis.MethodImplementationsTreeNode; | ||
| 30 | import cuchaz.enigma.analysis.MethodInheritanceTreeNode; | ||
| 31 | import cuchaz.enigma.mapping.BehaviorEntry; | ||
| 32 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 33 | import cuchaz.enigma.mapping.FieldEntry; | ||
| 34 | import cuchaz.enigma.mapping.MethodEntry; | ||
| 35 | import cuchaz.enigma.mapping.Translator; | ||
| 36 | |||
| 37 | public class TestJarIndexLoneClass { | ||
| 38 | |||
| 39 | private JarIndex m_index; | ||
| 40 | |||
| 41 | public TestJarIndexLoneClass() | ||
| 42 | throws Exception { | ||
| 43 | m_index = new JarIndex(); | ||
| 44 | m_index.indexJar(new JarFile("build/testLoneClass.obf.jar"), false); | ||
| 45 | } | ||
| 46 | |||
| 47 | @Test | ||
| 48 | public void obfEntries() { | ||
| 49 | assertThat(m_index.getObfClassEntries(), containsInAnyOrder( | ||
| 50 | newClass("cuchaz/enigma/inputs/Keep"), | ||
| 51 | newClass("none/a") | ||
| 52 | )); | ||
| 53 | } | ||
| 54 | |||
| 55 | @Test | ||
| 56 | public void translationIndex() { | ||
| 57 | assertThat(m_index.getTranslationIndex().getSuperclass(new ClassEntry("none/a")), is(nullValue())); | ||
| 58 | assertThat(m_index.getTranslationIndex().getSuperclass(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(nullValue())); | ||
| 59 | assertThat(m_index.getTranslationIndex().getAncestry(new ClassEntry("none/a")), is(empty())); | ||
| 60 | assertThat(m_index.getTranslationIndex().getAncestry(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(empty())); | ||
| 61 | assertThat(m_index.getTranslationIndex().getSubclass(new ClassEntry("none/a")), is(empty())); | ||
| 62 | assertThat(m_index.getTranslationIndex().getSubclass(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(empty())); | ||
| 63 | } | ||
| 64 | |||
| 65 | @Test | ||
| 66 | public void access() { | ||
| 67 | assertThat(m_index.getAccess(newField("none/a", "a")), is(Access.Private)); | ||
| 68 | assertThat(m_index.getAccess(newMethod("none/a", "a", "()Ljava/lang/String;")), is(Access.Public)); | ||
| 69 | assertThat(m_index.getAccess(newField("none/a", "b")), is(nullValue())); | ||
| 70 | } | ||
| 71 | |||
| 72 | @Test | ||
| 73 | public void classInheritance() { | ||
| 74 | ClassInheritanceTreeNode node = m_index.getClassInheritance(new Translator(), newClass("none/a")); | ||
| 75 | assertThat(node, is(not(nullValue()))); | ||
| 76 | assertThat(node.getObfClassName(), is("none/a")); | ||
| 77 | assertThat(node.getChildCount(), is(0)); | ||
| 78 | } | ||
| 79 | |||
| 80 | @Test | ||
| 81 | public void methodInheritance() { | ||
| 82 | MethodEntry source = newMethod("none/a", "a", "()Ljava/lang/String;"); | ||
| 83 | MethodInheritanceTreeNode node = m_index.getMethodInheritance(new Translator(), source); | ||
| 84 | assertThat(node, is(not(nullValue()))); | ||
| 85 | assertThat(node.getMethodEntry(), is(source)); | ||
| 86 | assertThat(node.getChildCount(), is(0)); | ||
| 87 | } | ||
| 88 | |||
| 89 | @Test | ||
| 90 | public void classImplementations() { | ||
| 91 | ClassImplementationsTreeNode node = m_index.getClassImplementations(new Translator(), newClass("none/a")); | ||
| 92 | assertThat(node, is(nullValue())); | ||
| 93 | } | ||
| 94 | |||
| 95 | @Test | ||
| 96 | public void methodImplementations() { | ||
| 97 | MethodEntry source = newMethod("none/a", "a", "()Ljava/lang/String;"); | ||
| 98 | MethodImplementationsTreeNode node = m_index.getMethodImplementations(new Translator(), source); | ||
| 99 | assertThat(node, is(nullValue())); | ||
| 100 | } | ||
| 101 | |||
| 102 | @Test | ||
| 103 | public void relatedMethodImplementations() { | ||
| 104 | Set<MethodEntry> entries = m_index.getRelatedMethodImplementations(newMethod("none/a", "a", "()Ljava/lang/String;")); | ||
| 105 | assertThat(entries, containsInAnyOrder( | ||
| 106 | newMethod("none/a", "a", "()Ljava/lang/String;") | ||
| 107 | )); | ||
| 108 | } | ||
| 109 | |||
| 110 | @Test | ||
| 111 | @SuppressWarnings("unchecked") | ||
| 112 | public void fieldReferences() { | ||
| 113 | FieldEntry source = newField("none/a", "a"); | ||
| 114 | Collection<EntryReference<FieldEntry,BehaviorEntry>> references = m_index.getFieldReferences(source); | ||
| 115 | assertThat(references, containsInAnyOrder( | ||
| 116 | newFieldReferenceByConstructor(source, "none/a", "(Ljava/lang/String;)V"), | ||
| 117 | newFieldReferenceByMethod(source, "none/a", "a", "()Ljava/lang/String;") | ||
| 118 | )); | ||
| 119 | } | ||
| 120 | |||
| 121 | @Test | ||
| 122 | public void behaviorReferences() { | ||
| 123 | assertThat(m_index.getBehaviorReferences(newMethod("none/a", "a", "()Ljava/lang/String;")), is(empty())); | ||
| 124 | } | ||
| 125 | |||
| 126 | @Test | ||
| 127 | public void innerClasses() { | ||
| 128 | assertThat(m_index.getInnerClasses("none/a"), is(empty())); | ||
| 129 | } | ||
| 130 | |||
| 131 | @Test | ||
| 132 | public void outerClass() { | ||
| 133 | assertThat(m_index.getOuterClass("a"), is(nullValue())); | ||
| 134 | } | ||
| 135 | |||
| 136 | @Test | ||
| 137 | public void isAnonymousClass() { | ||
| 138 | assertThat(m_index.isAnonymousClass("none/a"), is(false)); | ||
| 139 | } | ||
| 140 | |||
| 141 | @Test | ||
| 142 | public void interfaces() { | ||
| 143 | assertThat(m_index.getInterfaces("none/a"), is(empty())); | ||
| 144 | } | ||
| 145 | |||
| 146 | @Test | ||
| 147 | public void implementingClasses() { | ||
| 148 | assertThat(m_index.getImplementingClasses("none/a"), is(empty())); | ||
| 149 | } | ||
| 150 | |||
| 151 | @Test | ||
| 152 | public void isInterface() { | ||
| 153 | assertThat(m_index.isInterface("none/a"), is(false)); | ||
| 154 | } | ||
| 155 | |||
| 156 | @Test | ||
| 157 | public void contains() { | ||
| 158 | assertThat(m_index.containsObfClass(newClass("none/a")), is(true)); | ||
| 159 | assertThat(m_index.containsObfClass(newClass("none/b")), is(false)); | ||
| 160 | assertThat(m_index.containsObfField(newField("none/a", "a")), is(true)); | ||
| 161 | assertThat(m_index.containsObfField(newField("none/a", "b")), is(false)); | ||
| 162 | assertThat(m_index.containsObfBehavior(newMethod("none/a", "a", "()Ljava/lang/String;")), is(true)); | ||
| 163 | assertThat(m_index.containsObfBehavior(newMethod("none/a", "b", "()Ljava/lang/String;")), is(false)); | ||
| 164 | } | ||
| 165 | } | ||
diff --git a/test/cuchaz/enigma/TestSignature.java b/test/cuchaz/enigma/TestSignature.java new file mode 100644 index 0000000..183a4fd --- /dev/null +++ b/test/cuchaz/enigma/TestSignature.java | |||
| @@ -0,0 +1,266 @@ | |||
| 1 | package cuchaz.enigma; | ||
| 2 | |||
| 3 | import static org.hamcrest.MatcherAssert.*; | ||
| 4 | import static org.hamcrest.Matchers.*; | ||
| 5 | |||
| 6 | import org.junit.Test; | ||
| 7 | |||
| 8 | import cuchaz.enigma.mapping.ClassNameReplacer; | ||
| 9 | import cuchaz.enigma.mapping.Signature; | ||
| 10 | import cuchaz.enigma.mapping.Type; | ||
| 11 | |||
| 12 | |||
| 13 | public class TestSignature { | ||
| 14 | |||
| 15 | @Test | ||
| 16 | public void easiest() { | ||
| 17 | final Signature sig = new Signature("()V"); | ||
| 18 | assertThat(sig.getArgumentTypes(), is(empty())); | ||
| 19 | assertThat(sig.getReturnType(), is(new Type("V"))); | ||
| 20 | } | ||
| 21 | |||
| 22 | @Test | ||
| 23 | public void primitives() { | ||
| 24 | { | ||
| 25 | final Signature sig = new Signature("(I)V"); | ||
| 26 | assertThat(sig.getArgumentTypes(), contains( | ||
| 27 | new Type("I") | ||
| 28 | )); | ||
| 29 | assertThat(sig.getReturnType(), is(new Type("V"))); | ||
| 30 | } | ||
| 31 | { | ||
| 32 | final Signature sig = new Signature("(I)I"); | ||
| 33 | assertThat(sig.getArgumentTypes(), contains( | ||
| 34 | new Type("I") | ||
| 35 | )); | ||
| 36 | assertThat(sig.getReturnType(), is(new Type("I"))); | ||
| 37 | } | ||
| 38 | { | ||
| 39 | final Signature sig = new Signature("(IBCJ)Z"); | ||
| 40 | assertThat(sig.getArgumentTypes(), contains( | ||
| 41 | new Type("I"), | ||
| 42 | new Type("B"), | ||
| 43 | new Type("C"), | ||
| 44 | new Type("J") | ||
| 45 | )); | ||
| 46 | assertThat(sig.getReturnType(), is(new Type("Z"))); | ||
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 50 | @Test | ||
| 51 | public void classes() { | ||
| 52 | { | ||
| 53 | final Signature sig = new Signature("([LFoo;)V"); | ||
| 54 | assertThat(sig.getArgumentTypes().size(), is(1)); | ||
| 55 | assertThat(sig.getArgumentTypes().get(0), is(new Type("[LFoo;"))); | ||
| 56 | assertThat(sig.getReturnType(), is(new Type("V"))); | ||
| 57 | } | ||
| 58 | { | ||
| 59 | final Signature sig = new Signature("(LFoo;)LBar;"); | ||
| 60 | assertThat(sig.getArgumentTypes(), contains( | ||
| 61 | new Type("LFoo;") | ||
| 62 | )); | ||
| 63 | assertThat(sig.getReturnType(), is(new Type("LBar;"))); | ||
| 64 | } | ||
| 65 | { | ||
| 66 | final Signature sig = new Signature("(LFoo;LMoo;LZoo;)LBar;"); | ||
| 67 | assertThat(sig.getArgumentTypes(), contains( | ||
| 68 | new Type("LFoo;"), | ||
| 69 | new Type("LMoo;"), | ||
| 70 | new Type("LZoo;") | ||
| 71 | )); | ||
| 72 | assertThat(sig.getReturnType(), is(new Type("LBar;"))); | ||
| 73 | } | ||
| 74 | { | ||
| 75 | final Signature sig = new Signature("(LFoo<LParm;>;LMoo<LParm;>;)LBar<LParm;>;"); | ||
| 76 | assertThat(sig.getArgumentTypes(), contains( | ||
| 77 | new Type("LFoo<LParm;>;"), | ||
| 78 | new Type("LMoo<LParm;>;") | ||
| 79 | )); | ||
| 80 | assertThat(sig.getReturnType(), is(new Type("LBar<LParm;>;"))); | ||
| 81 | } | ||
| 82 | } | ||
| 83 | |||
| 84 | @Test | ||
| 85 | public void arrays() { | ||
| 86 | { | ||
| 87 | final Signature sig = new Signature("([I)V"); | ||
| 88 | assertThat(sig.getArgumentTypes(), contains( | ||
| 89 | new Type("[I") | ||
| 90 | )); | ||
| 91 | assertThat(sig.getReturnType(), is(new Type("V"))); | ||
| 92 | } | ||
| 93 | { | ||
| 94 | final Signature sig = new Signature("([I)[J"); | ||
| 95 | assertThat(sig.getArgumentTypes(), contains( | ||
| 96 | new Type("[I") | ||
| 97 | )); | ||
| 98 | assertThat(sig.getReturnType(), is(new Type("[J"))); | ||
| 99 | } | ||
| 100 | { | ||
| 101 | final Signature sig = new Signature("([I[Z[F)[D"); | ||
| 102 | assertThat(sig.getArgumentTypes(), contains( | ||
| 103 | new Type("[I"), | ||
| 104 | new Type("[Z"), | ||
| 105 | new Type("[F") | ||
| 106 | )); | ||
| 107 | assertThat(sig.getReturnType(), is(new Type("[D"))); | ||
| 108 | } | ||
| 109 | } | ||
| 110 | |||
| 111 | @Test | ||
| 112 | public void mixed() { | ||
| 113 | { | ||
| 114 | final Signature sig = new Signature("(I[JLFoo;)Z"); | ||
| 115 | assertThat(sig.getArgumentTypes(), contains( | ||
| 116 | new Type("I"), | ||
| 117 | new Type("[J"), | ||
| 118 | new Type("LFoo;") | ||
| 119 | )); | ||
| 120 | assertThat(sig.getReturnType(), is(new Type("Z"))); | ||
| 121 | } | ||
| 122 | { | ||
| 123 | final Signature sig = new Signature("(III)[LFoo;"); | ||
| 124 | assertThat(sig.getArgumentTypes(), contains( | ||
| 125 | new Type("I"), | ||
| 126 | new Type("I"), | ||
| 127 | new Type("I") | ||
| 128 | )); | ||
| 129 | assertThat(sig.getReturnType(), is(new Type("[LFoo;"))); | ||
| 130 | } | ||
| 131 | } | ||
| 132 | |||
| 133 | @Test | ||
| 134 | public void replaceClasses() { | ||
| 135 | { | ||
| 136 | final Signature oldSig = new Signature("()V"); | ||
| 137 | final Signature sig = new Signature(oldSig, new ClassNameReplacer() { | ||
| 138 | @Override | ||
| 139 | public String replace(String val) { | ||
| 140 | return null; | ||
| 141 | } | ||
| 142 | }); | ||
| 143 | assertThat(sig.getArgumentTypes(), is(empty())); | ||
| 144 | assertThat(sig.getReturnType(), is(new Type("V"))); | ||
| 145 | } | ||
| 146 | { | ||
| 147 | final Signature oldSig = new Signature("(IJLFoo;)V"); | ||
| 148 | final Signature sig = new Signature(oldSig, new ClassNameReplacer() { | ||
| 149 | @Override | ||
| 150 | public String replace(String val) { | ||
| 151 | return null; | ||
| 152 | } | ||
| 153 | }); | ||
| 154 | assertThat(sig.getArgumentTypes(), contains( | ||
| 155 | new Type("I"), | ||
| 156 | new Type("J"), | ||
| 157 | new Type("LFoo;") | ||
| 158 | )); | ||
| 159 | assertThat(sig.getReturnType(), is(new Type("V"))); | ||
| 160 | } | ||
| 161 | { | ||
| 162 | final Signature oldSig = new Signature("(LFoo;LBar;)LMoo;"); | ||
| 163 | final Signature sig = new Signature(oldSig, new ClassNameReplacer() { | ||
| 164 | @Override | ||
| 165 | public String replace(String val) { | ||
| 166 | if (val.equals("Foo")) { | ||
| 167 | return "Bar"; | ||
| 168 | } | ||
| 169 | return null; | ||
| 170 | } | ||
| 171 | }); | ||
| 172 | assertThat(sig.getArgumentTypes(), contains( | ||
| 173 | new Type("LBar;"), | ||
| 174 | new Type("LBar;") | ||
| 175 | )); | ||
| 176 | assertThat(sig.getReturnType(), is(new Type("LMoo;"))); | ||
| 177 | } | ||
| 178 | { | ||
| 179 | final Signature oldSig = new Signature("(LFoo;LBar;)LMoo;"); | ||
| 180 | final Signature sig = new Signature(oldSig, new ClassNameReplacer() { | ||
| 181 | @Override | ||
| 182 | public String replace(String val) { | ||
| 183 | if (val.equals("Moo")) { | ||
| 184 | return "Cow"; | ||
| 185 | } | ||
| 186 | return null; | ||
| 187 | } | ||
| 188 | }); | ||
| 189 | assertThat(sig.getArgumentTypes(), contains( | ||
| 190 | new Type("LFoo;"), | ||
| 191 | new Type("LBar;") | ||
| 192 | )); | ||
| 193 | assertThat(sig.getReturnType(), is(new Type("LCow;"))); | ||
| 194 | } | ||
| 195 | } | ||
| 196 | |||
| 197 | @Test | ||
| 198 | public void replaceArrayClasses() { | ||
| 199 | { | ||
| 200 | final Signature oldSig = new Signature("([LFoo;)[[[LBar;"); | ||
| 201 | final Signature sig = new Signature(oldSig, new ClassNameReplacer() { | ||
| 202 | @Override | ||
| 203 | public String replace(String val) { | ||
| 204 | if (val.equals("Foo")) { | ||
| 205 | return "Food"; | ||
| 206 | } else if (val.equals("Bar")) { | ||
| 207 | return "Beer"; | ||
| 208 | } | ||
| 209 | return null; | ||
| 210 | } | ||
| 211 | }); | ||
| 212 | assertThat(sig.getArgumentTypes(), contains( | ||
| 213 | new Type("[LFood;") | ||
| 214 | )); | ||
| 215 | assertThat(sig.getReturnType(), is(new Type("[[[LBeer;"))); | ||
| 216 | } | ||
| 217 | } | ||
| 218 | |||
| 219 | @Test | ||
| 220 | public void equals() { | ||
| 221 | |||
| 222 | // base | ||
| 223 | assertThat(new Signature("()V"), is(new Signature("()V"))); | ||
| 224 | |||
| 225 | // arguments | ||
| 226 | assertThat(new Signature("(I)V"), is(new Signature("(I)V"))); | ||
| 227 | assertThat(new Signature("(ZIZ)V"), is(new Signature("(ZIZ)V"))); | ||
| 228 | assertThat(new Signature("(LFoo;)V"), is(new Signature("(LFoo;)V"))); | ||
| 229 | assertThat(new Signature("(LFoo;LBar;)V"), is(new Signature("(LFoo;LBar;)V"))); | ||
| 230 | assertThat(new Signature("([I)V"), is(new Signature("([I)V"))); | ||
| 231 | assertThat(new Signature("([[D[[[J)V"), is(new Signature("([[D[[[J)V"))); | ||
| 232 | |||
| 233 | assertThat(new Signature("()V"), is(not(new Signature("(I)V")))); | ||
| 234 | assertThat(new Signature("(I)V"), is(not(new Signature("()V")))); | ||
| 235 | assertThat(new Signature("(IJ)V"), is(not(new Signature("(JI)V")))); | ||
| 236 | assertThat(new Signature("([[Z)V"), is(not(new Signature("([[LFoo;)V")))); | ||
| 237 | assertThat(new Signature("(LFoo;LBar;)V"), is(not(new Signature("(LFoo;LCow;)V")))); | ||
| 238 | assertThat(new Signature("([LFoo;LBar;)V"), is(not(new Signature("(LFoo;LCow;)V")))); | ||
| 239 | |||
| 240 | // return type | ||
| 241 | assertThat(new Signature("()I"), is(new Signature("()I"))); | ||
| 242 | assertThat(new Signature("()Z"), is(new Signature("()Z"))); | ||
| 243 | assertThat(new Signature("()[D"), is(new Signature("()[D"))); | ||
| 244 | assertThat(new Signature("()[[[Z"), is(new Signature("()[[[Z"))); | ||
| 245 | assertThat(new Signature("()LFoo;"), is(new Signature("()LFoo;"))); | ||
| 246 | assertThat(new Signature("()[LFoo;"), is(new Signature("()[LFoo;"))); | ||
| 247 | |||
| 248 | assertThat(new Signature("()I"), is(not(new Signature("()Z")))); | ||
| 249 | assertThat(new Signature("()Z"), is(not(new Signature("()I")))); | ||
| 250 | assertThat(new Signature("()[D"), is(not(new Signature("()[J")))); | ||
| 251 | assertThat(new Signature("()[[[Z"), is(not(new Signature("()[[Z")))); | ||
| 252 | assertThat(new Signature("()LFoo;"), is(not(new Signature("()LBar;")))); | ||
| 253 | assertThat(new Signature("()[LFoo;"), is(not(new Signature("()[LBar;")))); | ||
| 254 | } | ||
| 255 | |||
| 256 | @Test | ||
| 257 | public void testToString() { | ||
| 258 | assertThat(new Signature("()V").toString(), is("()V")); | ||
| 259 | assertThat(new Signature("(I)V").toString(), is("(I)V")); | ||
| 260 | assertThat(new Signature("(ZIZ)V").toString(), is("(ZIZ)V")); | ||
| 261 | assertThat(new Signature("(LFoo;)V").toString(), is("(LFoo;)V")); | ||
| 262 | assertThat(new Signature("(LFoo;LBar;)V").toString(), is("(LFoo;LBar;)V")); | ||
| 263 | assertThat(new Signature("([I)V").toString(), is("([I)V")); | ||
| 264 | assertThat(new Signature("([[D[[[J)V").toString(), is("([[D[[[J)V")); | ||
| 265 | } | ||
| 266 | } | ||
diff --git a/test/cuchaz/enigma/TestSourceIndex.java b/test/cuchaz/enigma/TestSourceIndex.java new file mode 100644 index 0000000..357acb6 --- /dev/null +++ b/test/cuchaz/enigma/TestSourceIndex.java | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2014 Jeff Martin. | ||
| 3 | * | ||
| 4 | * All rights reserved. This program and the accompanying materials | ||
| 5 | * are made available under the terms of the GNU Public License v3.0 | ||
| 6 | * which accompanies this distribution, and is available at | ||
| 7 | * http://www.gnu.org/licenses/gpl.html | ||
| 8 | * | ||
| 9 | * Contributors: | ||
| 10 | * Jeff Martin - initial API and implementation | ||
| 11 | ******************************************************************************/ | ||
| 12 | package cuchaz.enigma; | ||
| 13 | |||
| 14 | import java.util.Set; | ||
| 15 | import java.util.jar.JarFile; | ||
| 16 | |||
| 17 | import org.junit.Test; | ||
| 18 | |||
| 19 | import com.google.common.collect.Sets; | ||
| 20 | import com.strobel.decompiler.languages.java.ast.CompilationUnit; | ||
| 21 | |||
| 22 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 23 | |||
| 24 | public class TestSourceIndex { | ||
| 25 | |||
| 26 | // TEMP | ||
| 27 | //@Test | ||
| 28 | public void indexEverything() | ||
| 29 | throws Exception { | ||
| 30 | Deobfuscator deobfuscator = new Deobfuscator(new JarFile("input/1.8.jar")); | ||
| 31 | |||
| 32 | // get all classes that aren't inner classes | ||
| 33 | Set<ClassEntry> classEntries = Sets.newHashSet(); | ||
| 34 | for (ClassEntry obfClassEntry : deobfuscator.getJarIndex().getObfClassEntries()) { | ||
| 35 | if (!obfClassEntry.isInnerClass()) { | ||
| 36 | classEntries.add(obfClassEntry); | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | for (ClassEntry obfClassEntry : classEntries) { | ||
| 41 | try { | ||
| 42 | CompilationUnit tree = deobfuscator.getSourceTree(obfClassEntry.getName()); | ||
| 43 | String source = deobfuscator.getSource(tree); | ||
| 44 | deobfuscator.getSourceIndex(tree, source); | ||
| 45 | } catch (Throwable t) { | ||
| 46 | throw new Error("Unable to index " + obfClassEntry, t); | ||
| 47 | } | ||
| 48 | } | ||
| 49 | } | ||
| 50 | } | ||
diff --git a/test/cuchaz/enigma/TestTokensConstructors.java b/test/cuchaz/enigma/TestTokensConstructors.java new file mode 100644 index 0000000..6758d2a --- /dev/null +++ b/test/cuchaz/enigma/TestTokensConstructors.java | |||
| @@ -0,0 +1,136 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2014 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Public License v3.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/gpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma; | ||
| 12 | |||
| 13 | import static cuchaz.enigma.EntryFactory.*; | ||
| 14 | import static org.hamcrest.MatcherAssert.*; | ||
| 15 | import static org.hamcrest.Matchers.*; | ||
| 16 | |||
| 17 | import java.util.jar.JarFile; | ||
| 18 | |||
| 19 | import org.junit.Test; | ||
| 20 | |||
| 21 | import cuchaz.enigma.mapping.BehaviorEntry; | ||
| 22 | |||
| 23 | public class TestTokensConstructors extends TokenChecker { | ||
| 24 | |||
| 25 | public TestTokensConstructors() | ||
| 26 | throws Exception { | ||
| 27 | super(new JarFile("build/testConstructors.obf.jar")); | ||
| 28 | } | ||
| 29 | |||
| 30 | @Test | ||
| 31 | public void baseDeclarations() { | ||
| 32 | assertThat(getDeclarationToken(newConstructor("none/a", "()V")), is("a")); | ||
| 33 | assertThat(getDeclarationToken(newConstructor("none/a", "(I)V")), is("a")); | ||
| 34 | } | ||
| 35 | |||
| 36 | @Test | ||
| 37 | public void subDeclarations() { | ||
| 38 | assertThat(getDeclarationToken(newConstructor("none/d", "()V")), is("d")); | ||
| 39 | assertThat(getDeclarationToken(newConstructor("none/d", "(I)V")), is("d")); | ||
| 40 | assertThat(getDeclarationToken(newConstructor("none/d", "(II)V")), is("d")); | ||
| 41 | assertThat(getDeclarationToken(newConstructor("none/d", "(III)V")), is("d")); | ||
| 42 | } | ||
| 43 | |||
| 44 | @Test | ||
| 45 | public void subsubDeclarations() { | ||
| 46 | assertThat(getDeclarationToken(newConstructor("none/e", "(I)V")), is("e")); | ||
| 47 | } | ||
| 48 | |||
| 49 | @Test | ||
| 50 | public void defaultDeclarations() { | ||
| 51 | assertThat(getDeclarationToken(newConstructor("none/c", "()V")), nullValue()); | ||
| 52 | } | ||
| 53 | |||
| 54 | @Test | ||
| 55 | public void baseDefaultReferences() { | ||
| 56 | BehaviorEntry source = newConstructor("none/a", "()V"); | ||
| 57 | assertThat( | ||
| 58 | getReferenceTokens(newBehaviorReferenceByMethod(source, "none/b", "a", "()V")), | ||
| 59 | containsInAnyOrder("a") | ||
| 60 | ); | ||
| 61 | assertThat( | ||
| 62 | getReferenceTokens(newBehaviorReferenceByConstructor(source, "none/d", "()V")), | ||
| 63 | is(empty()) // implicit call, not decompiled to token | ||
| 64 | ); | ||
| 65 | assertThat( | ||
| 66 | getReferenceTokens(newBehaviorReferenceByConstructor(source, "none/d", "(III)V")), | ||
| 67 | is(empty()) // implicit call, not decompiled to token | ||
| 68 | ); | ||
| 69 | } | ||
| 70 | |||
| 71 | @Test | ||
| 72 | public void baseIntReferences() { | ||
| 73 | BehaviorEntry source = newConstructor("none/a", "(I)V"); | ||
| 74 | assertThat( | ||
| 75 | getReferenceTokens(newBehaviorReferenceByMethod(source, "none/b", "b", "()V")), | ||
| 76 | containsInAnyOrder("a") | ||
| 77 | ); | ||
| 78 | } | ||
| 79 | |||
| 80 | @Test | ||
| 81 | public void subDefaultReferences() { | ||
| 82 | BehaviorEntry source = newConstructor("none/d", "()V"); | ||
| 83 | assertThat( | ||
| 84 | getReferenceTokens(newBehaviorReferenceByMethod(source, "none/b", "c", "()V")), | ||
| 85 | containsInAnyOrder("d") | ||
| 86 | ); | ||
| 87 | assertThat( | ||
| 88 | getReferenceTokens(newBehaviorReferenceByConstructor(source, "none/d", "(I)V")), | ||
| 89 | containsInAnyOrder("this") | ||
| 90 | ); | ||
| 91 | } | ||
| 92 | |||
| 93 | @Test | ||
| 94 | public void subIntReferences() { | ||
| 95 | BehaviorEntry source = newConstructor("none/d", "(I)V"); | ||
| 96 | assertThat(getReferenceTokens( | ||
| 97 | newBehaviorReferenceByMethod(source, "none/b", "d", "()V")), | ||
| 98 | containsInAnyOrder("d") | ||
| 99 | ); | ||
| 100 | assertThat(getReferenceTokens( | ||
| 101 | newBehaviorReferenceByConstructor(source, "none/d", "(II)V")), | ||
| 102 | containsInAnyOrder("this") | ||
| 103 | ); | ||
| 104 | assertThat(getReferenceTokens( | ||
| 105 | newBehaviorReferenceByConstructor(source, "none/e", "(I)V")), | ||
| 106 | containsInAnyOrder("super") | ||
| 107 | ); | ||
| 108 | } | ||
| 109 | |||
| 110 | @Test | ||
| 111 | public void subIntIntReferences() { | ||
| 112 | BehaviorEntry source = newConstructor("none/d", "(II)V"); | ||
| 113 | assertThat( | ||
| 114 | getReferenceTokens(newBehaviorReferenceByMethod(source, "none/b", "e", "()V")), | ||
| 115 | containsInAnyOrder("d") | ||
| 116 | ); | ||
| 117 | } | ||
| 118 | |||
| 119 | @Test | ||
| 120 | public void subsubIntReferences() { | ||
| 121 | BehaviorEntry source = newConstructor("none/e", "(I)V"); | ||
| 122 | assertThat( | ||
| 123 | getReferenceTokens(newBehaviorReferenceByMethod(source, "none/b", "f", "()V")), | ||
| 124 | containsInAnyOrder("e") | ||
| 125 | ); | ||
| 126 | } | ||
| 127 | |||
| 128 | @Test | ||
| 129 | public void defaultConstructableReferences() { | ||
| 130 | BehaviorEntry source = newConstructor("none/c", "()V"); | ||
| 131 | assertThat( | ||
| 132 | getReferenceTokens(newBehaviorReferenceByMethod(source, "none/b", "g", "()V")), | ||
| 133 | containsInAnyOrder("c") | ||
| 134 | ); | ||
| 135 | } | ||
| 136 | } | ||
diff --git a/test/cuchaz/enigma/TestTranslator.java b/test/cuchaz/enigma/TestTranslator.java new file mode 100644 index 0000000..290f6f0 --- /dev/null +++ b/test/cuchaz/enigma/TestTranslator.java | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | package cuchaz.enigma; | ||
| 2 | |||
| 3 | import static cuchaz.enigma.EntryFactory.*; | ||
| 4 | import static org.hamcrest.MatcherAssert.*; | ||
| 5 | import static org.hamcrest.Matchers.*; | ||
| 6 | |||
| 7 | import java.io.InputStream; | ||
| 8 | import java.io.InputStreamReader; | ||
| 9 | import java.util.jar.JarFile; | ||
| 10 | |||
| 11 | import org.junit.Test; | ||
| 12 | |||
| 13 | import cuchaz.enigma.mapping.Mappings; | ||
| 14 | import cuchaz.enigma.mapping.MappingsReader; | ||
| 15 | import cuchaz.enigma.mapping.TranslationDirection; | ||
| 16 | import cuchaz.enigma.mapping.Translator; | ||
| 17 | |||
| 18 | |||
| 19 | public class TestTranslator { | ||
| 20 | |||
| 21 | private Deobfuscator m_deobfuscator; | ||
| 22 | private Mappings m_mappings; | ||
| 23 | |||
| 24 | public TestTranslator() | ||
| 25 | throws Exception { | ||
| 26 | m_deobfuscator = new Deobfuscator(new JarFile("build/testTranslation.obf.jar")); | ||
| 27 | try (InputStream in = getClass().getResourceAsStream("/cuchaz/enigma/resources/translation.mappings")) { | ||
| 28 | m_mappings = new MappingsReader().read(new InputStreamReader(in)); | ||
| 29 | m_deobfuscator.setMappings(m_mappings); | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | @Test | ||
| 34 | public void deobfuscatingTranslations() | ||
| 35 | throws Exception { | ||
| 36 | Translator translator = m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating); | ||
| 37 | assertThat(translator.translateEntry(newClass("none/a")), is(newClass("deobf/A"))); | ||
| 38 | } | ||
| 39 | } | ||
diff --git a/test/cuchaz/enigma/TestType.java b/test/cuchaz/enigma/TestType.java new file mode 100644 index 0000000..7c3cebe --- /dev/null +++ b/test/cuchaz/enigma/TestType.java | |||
| @@ -0,0 +1,229 @@ | |||
| 1 | package cuchaz.enigma; | ||
| 2 | |||
| 3 | import org.junit.Test; | ||
| 4 | |||
| 5 | import static org.hamcrest.MatcherAssert.*; | ||
| 6 | import static org.hamcrest.Matchers.*; | ||
| 7 | |||
| 8 | import cuchaz.enigma.mapping.Type; | ||
| 9 | |||
| 10 | import static cuchaz.enigma.EntryFactory.*; | ||
| 11 | |||
| 12 | |||
| 13 | public class TestType { | ||
| 14 | |||
| 15 | @Test | ||
| 16 | public void isVoid() { | ||
| 17 | assertThat(new Type("V").isVoid(), is(true)); | ||
| 18 | assertThat(new Type("Z").isVoid(), is(false)); | ||
| 19 | assertThat(new Type("B").isVoid(), is(false)); | ||
| 20 | assertThat(new Type("C").isVoid(), is(false)); | ||
| 21 | assertThat(new Type("I").isVoid(), is(false)); | ||
| 22 | assertThat(new Type("J").isVoid(), is(false)); | ||
| 23 | assertThat(new Type("F").isVoid(), is(false)); | ||
| 24 | assertThat(new Type("D").isVoid(), is(false)); | ||
| 25 | assertThat(new Type("LFoo;").isVoid(), is(false)); | ||
| 26 | assertThat(new Type("[I").isVoid(), is(false)); | ||
| 27 | } | ||
| 28 | |||
| 29 | @Test | ||
| 30 | public void isPrimitive() { | ||
| 31 | assertThat(new Type("V").isPrimitive(), is(false)); | ||
| 32 | assertThat(new Type("Z").isPrimitive(), is(true)); | ||
| 33 | assertThat(new Type("B").isPrimitive(), is(true)); | ||
| 34 | assertThat(new Type("C").isPrimitive(), is(true)); | ||
| 35 | assertThat(new Type("I").isPrimitive(), is(true)); | ||
| 36 | assertThat(new Type("J").isPrimitive(), is(true)); | ||
| 37 | assertThat(new Type("F").isPrimitive(), is(true)); | ||
| 38 | assertThat(new Type("D").isPrimitive(), is(true)); | ||
| 39 | assertThat(new Type("LFoo;").isPrimitive(), is(false)); | ||
| 40 | assertThat(new Type("[I").isPrimitive(), is(false)); | ||
| 41 | } | ||
| 42 | |||
| 43 | @Test | ||
| 44 | public void getPrimitive() { | ||
| 45 | assertThat(new Type("Z").getPrimitive(), is(Type.Primitive.Boolean)); | ||
| 46 | assertThat(new Type("B").getPrimitive(), is(Type.Primitive.Byte)); | ||
| 47 | assertThat(new Type("C").getPrimitive(), is(Type.Primitive.Character)); | ||
| 48 | assertThat(new Type("I").getPrimitive(), is(Type.Primitive.Integer)); | ||
| 49 | assertThat(new Type("J").getPrimitive(), is(Type.Primitive.Long)); | ||
| 50 | assertThat(new Type("F").getPrimitive(), is(Type.Primitive.Float)); | ||
| 51 | assertThat(new Type("D").getPrimitive(), is(Type.Primitive.Double)); | ||
| 52 | } | ||
| 53 | |||
| 54 | @Test | ||
| 55 | public void isClass() { | ||
| 56 | assertThat(new Type("V").isClass(), is(false)); | ||
| 57 | assertThat(new Type("Z").isClass(), is(false)); | ||
| 58 | assertThat(new Type("B").isClass(), is(false)); | ||
| 59 | assertThat(new Type("C").isClass(), is(false)); | ||
| 60 | assertThat(new Type("I").isClass(), is(false)); | ||
| 61 | assertThat(new Type("J").isClass(), is(false)); | ||
| 62 | assertThat(new Type("F").isClass(), is(false)); | ||
| 63 | assertThat(new Type("D").isClass(), is(false)); | ||
| 64 | assertThat(new Type("LFoo;").isClass(), is(true)); | ||
| 65 | assertThat(new Type("[I").isClass(), is(false)); | ||
| 66 | } | ||
| 67 | |||
| 68 | @Test | ||
| 69 | public void getClassEntry() { | ||
| 70 | assertThat(new Type("LFoo;").getClassEntry(), is(newClass("Foo"))); | ||
| 71 | assertThat(new Type("LFoo<Ljava/lang/String;>;").getClassEntry(), is(newClass("Foo"))); | ||
| 72 | } | ||
| 73 | |||
| 74 | @Test | ||
| 75 | public void getArrayClassEntry() { | ||
| 76 | assertThat(new Type("[LFoo;").getClassEntry(), is(newClass("Foo"))); | ||
| 77 | assertThat(new Type("[[[LFoo<Ljava/lang/String;>;").getClassEntry(), is(newClass("Foo"))); | ||
| 78 | } | ||
| 79 | |||
| 80 | @Test | ||
| 81 | public void isArray() { | ||
| 82 | assertThat(new Type("V").isArray(), is(false)); | ||
| 83 | assertThat(new Type("Z").isArray(), is(false)); | ||
| 84 | assertThat(new Type("B").isArray(), is(false)); | ||
| 85 | assertThat(new Type("C").isArray(), is(false)); | ||
| 86 | assertThat(new Type("I").isArray(), is(false)); | ||
| 87 | assertThat(new Type("J").isArray(), is(false)); | ||
| 88 | assertThat(new Type("F").isArray(), is(false)); | ||
| 89 | assertThat(new Type("D").isArray(), is(false)); | ||
| 90 | assertThat(new Type("LFoo;").isArray(), is(false)); | ||
| 91 | assertThat(new Type("[I").isArray(), is(true)); | ||
| 92 | } | ||
| 93 | |||
| 94 | @Test | ||
| 95 | public void getArrayDimension() { | ||
| 96 | assertThat(new Type("[I").getArrayDimension(), is(1)); | ||
| 97 | assertThat(new Type("[[I").getArrayDimension(), is(2)); | ||
| 98 | assertThat(new Type("[[[I").getArrayDimension(), is(3)); | ||
| 99 | } | ||
| 100 | |||
| 101 | @Test | ||
| 102 | public void getArrayType() { | ||
| 103 | assertThat(new Type("[I").getArrayType(), is(new Type("I"))); | ||
| 104 | assertThat(new Type("[[I").getArrayType(), is(new Type("I"))); | ||
| 105 | assertThat(new Type("[[[I").getArrayType(), is(new Type("I"))); | ||
| 106 | assertThat(new Type("[Ljava/lang/String;").getArrayType(), is(new Type("Ljava/lang/String;"))); | ||
| 107 | } | ||
| 108 | |||
| 109 | @Test | ||
| 110 | public void hasClass() { | ||
| 111 | assertThat(new Type("LFoo;").hasClass(), is(true)); | ||
| 112 | assertThat(new Type("LCow<LCheese;>;").hasClass(), is(true)); | ||
| 113 | assertThat(new Type("[LBar;").hasClass(), is(true)); | ||
| 114 | assertThat(new Type("[[[LCat;").hasClass(), is(true)); | ||
| 115 | |||
| 116 | assertThat(new Type("V").hasClass(), is(false)); | ||
| 117 | assertThat(new Type("[I").hasClass(), is(false)); | ||
| 118 | assertThat(new Type("[[[I").hasClass(), is(false)); | ||
| 119 | assertThat(new Type("Z").hasClass(), is(false)); | ||
| 120 | } | ||
| 121 | |||
| 122 | @Test | ||
| 123 | public void parseVoid() { | ||
| 124 | final String answer = "V"; | ||
| 125 | assertThat(Type.parseFirst("V"), is(answer)); | ||
| 126 | assertThat(Type.parseFirst("VVV"), is(answer)); | ||
| 127 | assertThat(Type.parseFirst("VIJ"), is(answer)); | ||
| 128 | assertThat(Type.parseFirst("V[I"), is(answer)); | ||
| 129 | assertThat(Type.parseFirst("VLFoo;"), is(answer)); | ||
| 130 | assertThat(Type.parseFirst("V[LFoo;"), is(answer)); | ||
| 131 | } | ||
| 132 | |||
| 133 | @Test | ||
| 134 | public void parsePrimitive() { | ||
| 135 | final String answer = "I"; | ||
| 136 | assertThat(Type.parseFirst("I"), is(answer)); | ||
| 137 | assertThat(Type.parseFirst("III"), is(answer)); | ||
| 138 | assertThat(Type.parseFirst("IJZ"), is(answer)); | ||
| 139 | assertThat(Type.parseFirst("I[I"), is(answer)); | ||
| 140 | assertThat(Type.parseFirst("ILFoo;"), is(answer)); | ||
| 141 | assertThat(Type.parseFirst("I[LFoo;"), is(answer)); | ||
| 142 | } | ||
| 143 | |||
| 144 | @Test | ||
| 145 | public void parseClass() { | ||
| 146 | { | ||
| 147 | final String answer = "LFoo;"; | ||
| 148 | assertThat(Type.parseFirst("LFoo;"), is(answer)); | ||
| 149 | assertThat(Type.parseFirst("LFoo;I"), is(answer)); | ||
| 150 | assertThat(Type.parseFirst("LFoo;JZ"), is(answer)); | ||
| 151 | assertThat(Type.parseFirst("LFoo;[I"), is(answer)); | ||
| 152 | assertThat(Type.parseFirst("LFoo;LFoo;"), is(answer)); | ||
| 153 | assertThat(Type.parseFirst("LFoo;[LFoo;"), is(answer)); | ||
| 154 | } | ||
| 155 | { | ||
| 156 | final String answer = "LFoo<LFoo;>;"; | ||
| 157 | assertThat(Type.parseFirst("LFoo<LFoo;>;"), is(answer)); | ||
| 158 | assertThat(Type.parseFirst("LFoo<LFoo;>;I"), is(answer)); | ||
| 159 | assertThat(Type.parseFirst("LFoo<LFoo;>;JZ"), is(answer)); | ||
| 160 | assertThat(Type.parseFirst("LFoo<LFoo;>;[I"), is(answer)); | ||
| 161 | assertThat(Type.parseFirst("LFoo<LFoo;>;LFoo;"), is(answer)); | ||
| 162 | assertThat(Type.parseFirst("LFoo<LFoo;>;[LFoo;"), is(answer)); | ||
| 163 | } | ||
| 164 | { | ||
| 165 | final String answer = "LFoo<LFoo;,LBar;>;"; | ||
| 166 | assertThat(Type.parseFirst("LFoo<LFoo;,LBar;>;"), is(answer)); | ||
| 167 | assertThat(Type.parseFirst("LFoo<LFoo;,LBar;>;I"), is(answer)); | ||
| 168 | assertThat(Type.parseFirst("LFoo<LFoo;,LBar;>;JZ"), is(answer)); | ||
| 169 | assertThat(Type.parseFirst("LFoo<LFoo;,LBar;>;[I"), is(answer)); | ||
| 170 | assertThat(Type.parseFirst("LFoo<LFoo;,LBar;>;LFoo;"), is(answer)); | ||
| 171 | assertThat(Type.parseFirst("LFoo<LFoo;,LBar;>;[LFoo;"), is(answer)); | ||
| 172 | } | ||
| 173 | } | ||
| 174 | |||
| 175 | @Test | ||
| 176 | public void parseArray() { | ||
| 177 | { | ||
| 178 | final String answer = "[I"; | ||
| 179 | assertThat(Type.parseFirst("[I"), is(answer)); | ||
| 180 | assertThat(Type.parseFirst("[III"), is(answer)); | ||
| 181 | assertThat(Type.parseFirst("[IJZ"), is(answer)); | ||
| 182 | assertThat(Type.parseFirst("[I[I"), is(answer)); | ||
| 183 | assertThat(Type.parseFirst("[ILFoo;"), is(answer)); | ||
| 184 | } | ||
| 185 | { | ||
| 186 | final String answer = "[[I"; | ||
| 187 | assertThat(Type.parseFirst("[[I"), is(answer)); | ||
| 188 | assertThat(Type.parseFirst("[[III"), is(answer)); | ||
| 189 | assertThat(Type.parseFirst("[[IJZ"), is(answer)); | ||
| 190 | assertThat(Type.parseFirst("[[I[I"), is(answer)); | ||
| 191 | assertThat(Type.parseFirst("[[ILFoo;"), is(answer)); | ||
| 192 | } | ||
| 193 | { | ||
| 194 | final String answer = "[LFoo;"; | ||
| 195 | assertThat(Type.parseFirst("[LFoo;"), is(answer)); | ||
| 196 | assertThat(Type.parseFirst("[LFoo;II"), is(answer)); | ||
| 197 | assertThat(Type.parseFirst("[LFoo;JZ"), is(answer)); | ||
| 198 | assertThat(Type.parseFirst("[LFoo;[I"), is(answer)); | ||
| 199 | assertThat(Type.parseFirst("[LFoo;LFoo;"), is(answer)); | ||
| 200 | } | ||
| 201 | } | ||
| 202 | |||
| 203 | @Test | ||
| 204 | public void equals() { | ||
| 205 | assertThat(new Type("V"), is(new Type("V"))); | ||
| 206 | assertThat(new Type("Z"), is(new Type("Z"))); | ||
| 207 | assertThat(new Type("B"), is(new Type("B"))); | ||
| 208 | assertThat(new Type("C"), is(new Type("C"))); | ||
| 209 | assertThat(new Type("I"), is(new Type("I"))); | ||
| 210 | assertThat(new Type("J"), is(new Type("J"))); | ||
| 211 | assertThat(new Type("F"), is(new Type("F"))); | ||
| 212 | assertThat(new Type("D"), is(new Type("D"))); | ||
| 213 | assertThat(new Type("LFoo;"), is(new Type("LFoo;"))); | ||
| 214 | assertThat(new Type("[I"), is(new Type("[I"))); | ||
| 215 | assertThat(new Type("[[[I"), is(new Type("[[[I"))); | ||
| 216 | assertThat(new Type("[LFoo;"), is(new Type("[LFoo;"))); | ||
| 217 | assertThat(new Type("LFoo<LBar;>;"), is(new Type("LFoo<LBar;>;"))); | ||
| 218 | |||
| 219 | assertThat(new Type("V"), is(not(new Type("I")))); | ||
| 220 | assertThat(new Type("I"), is(not(new Type("J")))); | ||
| 221 | assertThat(new Type("I"), is(not(new Type("LBar;")))); | ||
| 222 | assertThat(new Type("I"), is(not(new Type("[I")))); | ||
| 223 | assertThat(new Type("LFoo;"), is(not(new Type("LBar;")))); | ||
| 224 | assertThat(new Type("LFoo<LBar;>;"), is(not(new Type("LFoo<LCow;>;")))); | ||
| 225 | assertThat(new Type("[I"), is(not(new Type("[Z")))); | ||
| 226 | assertThat(new Type("[[[I"), is(not(new Type("[I")))); | ||
| 227 | assertThat(new Type("[LFoo;"), is(not(new Type("[LBar;")))); | ||
| 228 | } | ||
| 229 | } | ||
diff --git a/test/cuchaz/enigma/TokenChecker.java b/test/cuchaz/enigma/TokenChecker.java new file mode 100644 index 0000000..a72c2fc --- /dev/null +++ b/test/cuchaz/enigma/TokenChecker.java | |||
| @@ -0,0 +1,65 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2014 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Public License v3.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/gpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma; | ||
| 12 | |||
| 13 | import java.io.IOException; | ||
| 14 | import java.util.Collection; | ||
| 15 | import java.util.List; | ||
| 16 | import java.util.jar.JarFile; | ||
| 17 | |||
| 18 | import com.google.common.collect.Lists; | ||
| 19 | import com.strobel.decompiler.languages.java.ast.CompilationUnit; | ||
| 20 | |||
| 21 | import cuchaz.enigma.analysis.EntryReference; | ||
| 22 | import cuchaz.enigma.analysis.SourceIndex; | ||
| 23 | import cuchaz.enigma.analysis.Token; | ||
| 24 | import cuchaz.enigma.mapping.Entry; | ||
| 25 | |||
| 26 | public class TokenChecker { | ||
| 27 | |||
| 28 | private Deobfuscator m_deobfuscator; | ||
| 29 | |||
| 30 | protected TokenChecker(JarFile jarFile) | ||
| 31 | throws IOException { | ||
| 32 | m_deobfuscator = new Deobfuscator(jarFile); | ||
| 33 | } | ||
| 34 | |||
| 35 | protected String getDeclarationToken(Entry entry) { | ||
| 36 | // decompile the class | ||
| 37 | CompilationUnit tree = m_deobfuscator.getSourceTree(entry.getClassName()); | ||
| 38 | // DEBUG | ||
| 39 | // tree.acceptVisitor( new TreeDumpVisitor( new File( "tree." + entry.getClassName().replace( '/', '.' ) + ".txt" ) ), null ); | ||
| 40 | String source = m_deobfuscator.getSource(tree); | ||
| 41 | SourceIndex index = m_deobfuscator.getSourceIndex(tree, source); | ||
| 42 | |||
| 43 | // get the token value | ||
| 44 | Token token = index.getDeclarationToken(entry); | ||
| 45 | if (token == null) { | ||
| 46 | return null; | ||
| 47 | } | ||
| 48 | return source.substring(token.start, token.end); | ||
| 49 | } | ||
| 50 | |||
| 51 | @SuppressWarnings("unchecked") | ||
| 52 | protected Collection<String> getReferenceTokens(EntryReference<? extends Entry,? extends Entry> reference) { | ||
| 53 | // decompile the class | ||
| 54 | CompilationUnit tree = m_deobfuscator.getSourceTree(reference.context.getClassName()); | ||
| 55 | String source = m_deobfuscator.getSource(tree); | ||
| 56 | SourceIndex index = m_deobfuscator.getSourceIndex(tree, source); | ||
| 57 | |||
| 58 | // get the token values | ||
| 59 | List<String> values = Lists.newArrayList(); | ||
| 60 | for (Token token : index.getReferenceTokens((EntryReference<Entry,Entry>)reference)) { | ||
| 61 | values.add(source.substring(token.start, token.end)); | ||
| 62 | } | ||
| 63 | return values; | ||
| 64 | } | ||
| 65 | } | ||
diff --git a/test/cuchaz/enigma/inputs/Keep.java b/test/cuchaz/enigma/inputs/Keep.java new file mode 100644 index 0000000..390e82f --- /dev/null +++ b/test/cuchaz/enigma/inputs/Keep.java | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | package cuchaz.enigma.inputs; | ||
| 2 | |||
| 3 | public class Keep { | ||
| 4 | public static void main(String[] args) { | ||
| 5 | System.out.println("Keep me!"); | ||
| 6 | } | ||
| 7 | } | ||
diff --git a/test/cuchaz/enigma/inputs/constructors/BaseClass.java b/test/cuchaz/enigma/inputs/constructors/BaseClass.java new file mode 100644 index 0000000..9345308 --- /dev/null +++ b/test/cuchaz/enigma/inputs/constructors/BaseClass.java | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | package cuchaz.enigma.inputs.constructors; | ||
| 2 | |||
| 3 | // none/a | ||
| 4 | public class BaseClass { | ||
| 5 | |||
| 6 | // <init>()V | ||
| 7 | public BaseClass() { | ||
| 8 | System.out.println("Default constructor"); | ||
| 9 | } | ||
| 10 | |||
| 11 | // <init>(I)V | ||
| 12 | public BaseClass(int i) { | ||
| 13 | System.out.println("Int constructor " + i); | ||
| 14 | } | ||
| 15 | } | ||
diff --git a/test/cuchaz/enigma/inputs/constructors/Caller.java b/test/cuchaz/enigma/inputs/constructors/Caller.java new file mode 100644 index 0000000..5727875 --- /dev/null +++ b/test/cuchaz/enigma/inputs/constructors/Caller.java | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | package cuchaz.enigma.inputs.constructors; | ||
| 2 | |||
| 3 | // none/b | ||
| 4 | public class Caller { | ||
| 5 | |||
| 6 | // a()V | ||
| 7 | public void callBaseDefault() { | ||
| 8 | // none/a.<init>()V | ||
| 9 | System.out.println(new BaseClass()); | ||
| 10 | } | ||
| 11 | |||
| 12 | // b()V | ||
| 13 | public void callBaseInt() { | ||
| 14 | // none/a.<init>(I)V | ||
| 15 | System.out.println(new BaseClass(5)); | ||
| 16 | } | ||
| 17 | |||
| 18 | // c()V | ||
| 19 | public void callSubDefault() { | ||
| 20 | // none/d.<init>()V | ||
| 21 | System.out.println(new SubClass()); | ||
| 22 | } | ||
| 23 | |||
| 24 | // d()V | ||
| 25 | public void callSubInt() { | ||
| 26 | // none/d.<init>(I)V | ||
| 27 | System.out.println(new SubClass(6)); | ||
| 28 | } | ||
| 29 | |||
| 30 | // e()V | ||
| 31 | public void callSubIntInt() { | ||
| 32 | // none/d.<init>(II)V | ||
| 33 | System.out.println(new SubClass(4, 2)); | ||
| 34 | } | ||
| 35 | |||
| 36 | // f()V | ||
| 37 | public void callSubSubInt() { | ||
| 38 | // none/e.<init>(I)V | ||
| 39 | System.out.println(new SubSubClass(3)); | ||
| 40 | } | ||
| 41 | |||
| 42 | // g()V | ||
| 43 | public void callDefaultConstructable() { | ||
| 44 | // none/c.<init>()V | ||
| 45 | System.out.println(new DefaultConstructable()); | ||
| 46 | } | ||
| 47 | } | ||
diff --git a/test/cuchaz/enigma/inputs/constructors/DefaultConstructable.java b/test/cuchaz/enigma/inputs/constructors/DefaultConstructable.java new file mode 100644 index 0000000..26a3ddb --- /dev/null +++ b/test/cuchaz/enigma/inputs/constructors/DefaultConstructable.java | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | package cuchaz.enigma.inputs.constructors; | ||
| 2 | |||
| 3 | public class DefaultConstructable { | ||
| 4 | // only default constructor | ||
| 5 | } | ||
diff --git a/test/cuchaz/enigma/inputs/constructors/SubClass.java b/test/cuchaz/enigma/inputs/constructors/SubClass.java new file mode 100644 index 0000000..fecfa2b --- /dev/null +++ b/test/cuchaz/enigma/inputs/constructors/SubClass.java | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | package cuchaz.enigma.inputs.constructors; | ||
| 2 | |||
| 3 | // none/d extends none/a | ||
| 4 | public class SubClass extends BaseClass { | ||
| 5 | |||
| 6 | // <init>()V | ||
| 7 | public SubClass() { | ||
| 8 | // none/a.<init>()V | ||
| 9 | } | ||
| 10 | |||
| 11 | // <init>(I)V | ||
| 12 | public SubClass(int num) { | ||
| 13 | // <init>()V | ||
| 14 | this(); | ||
| 15 | System.out.println("SubClass " + num); | ||
| 16 | } | ||
| 17 | |||
| 18 | // <init>(II)V | ||
| 19 | public SubClass(int a, int b) { | ||
| 20 | // <init>(I)V | ||
| 21 | this(a + b); | ||
| 22 | } | ||
| 23 | |||
| 24 | // <init>(III)V | ||
| 25 | public SubClass(int a, int b, int c) { | ||
| 26 | // none/a.<init>()V | ||
| 27 | } | ||
| 28 | } | ||
diff --git a/test/cuchaz/enigma/inputs/constructors/SubSubClass.java b/test/cuchaz/enigma/inputs/constructors/SubSubClass.java new file mode 100644 index 0000000..ab84161 --- /dev/null +++ b/test/cuchaz/enigma/inputs/constructors/SubSubClass.java | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | package cuchaz.enigma.inputs.constructors; | ||
| 2 | |||
| 3 | // none/e extends none/d | ||
| 4 | public class SubSubClass extends SubClass { | ||
| 5 | |||
| 6 | // <init>(I)V | ||
| 7 | public SubSubClass(int i) { | ||
| 8 | // none/c.<init>(I)V | ||
| 9 | super(i); | ||
| 10 | } | ||
| 11 | } | ||
diff --git a/test/cuchaz/enigma/inputs/inheritanceTree/BaseClass.java b/test/cuchaz/enigma/inputs/inheritanceTree/BaseClass.java new file mode 100644 index 0000000..5b416c4 --- /dev/null +++ b/test/cuchaz/enigma/inputs/inheritanceTree/BaseClass.java | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | package cuchaz.enigma.inputs.inheritanceTree; | ||
| 2 | |||
| 3 | // none/a | ||
| 4 | public abstract class BaseClass { | ||
| 5 | |||
| 6 | // a | ||
| 7 | private String m_name; | ||
| 8 | |||
| 9 | // <init>(Ljava/lang/String;)V | ||
| 10 | protected BaseClass(String name) { | ||
| 11 | m_name = name; | ||
| 12 | } | ||
| 13 | |||
| 14 | // a()Ljava/lang/String; | ||
| 15 | public String getName() { | ||
| 16 | return m_name; | ||
| 17 | } | ||
| 18 | |||
| 19 | // a()V | ||
| 20 | public abstract void doBaseThings(); | ||
| 21 | } | ||
diff --git a/test/cuchaz/enigma/inputs/inheritanceTree/SubclassA.java b/test/cuchaz/enigma/inputs/inheritanceTree/SubclassA.java new file mode 100644 index 0000000..7a99d51 --- /dev/null +++ b/test/cuchaz/enigma/inputs/inheritanceTree/SubclassA.java | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | package cuchaz.enigma.inputs.inheritanceTree; | ||
| 2 | |||
| 3 | // none/b extends none/a | ||
| 4 | public abstract class SubclassA extends BaseClass { | ||
| 5 | |||
| 6 | // <init>(Ljava/lang/String;)V | ||
| 7 | protected SubclassA(String name) { | ||
| 8 | // call to none/a.<init>(Ljava/lang/String)V | ||
| 9 | super(name); | ||
| 10 | } | ||
| 11 | } | ||
diff --git a/test/cuchaz/enigma/inputs/inheritanceTree/SubclassB.java b/test/cuchaz/enigma/inputs/inheritanceTree/SubclassB.java new file mode 100644 index 0000000..c9485d3 --- /dev/null +++ b/test/cuchaz/enigma/inputs/inheritanceTree/SubclassB.java | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | package cuchaz.enigma.inputs.inheritanceTree; | ||
| 2 | |||
| 3 | // none/c extends none/a | ||
| 4 | public class SubclassB extends BaseClass { | ||
| 5 | |||
| 6 | // a | ||
| 7 | private int m_numThings; | ||
| 8 | |||
| 9 | // <init>()V | ||
| 10 | protected SubclassB() { | ||
| 11 | // none/a.<init>(Ljava/lang/String;)V | ||
| 12 | super("B"); | ||
| 13 | |||
| 14 | // access to a | ||
| 15 | m_numThings = 4; | ||
| 16 | } | ||
| 17 | |||
| 18 | @Override | ||
| 19 | // a()V | ||
| 20 | public void doBaseThings() { | ||
| 21 | // call to none/a.a()Ljava/lang/String; | ||
| 22 | System.out.println("Base things by B! " + getName()); | ||
| 23 | } | ||
| 24 | |||
| 25 | // b()V | ||
| 26 | public void doBThings() { | ||
| 27 | // access to a | ||
| 28 | System.out.println("" + m_numThings + " B things!"); | ||
| 29 | } | ||
| 30 | } | ||
diff --git a/test/cuchaz/enigma/inputs/inheritanceTree/SubsubclassAA.java b/test/cuchaz/enigma/inputs/inheritanceTree/SubsubclassAA.java new file mode 100644 index 0000000..afd03ac --- /dev/null +++ b/test/cuchaz/enigma/inputs/inheritanceTree/SubsubclassAA.java | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | package cuchaz.enigma.inputs.inheritanceTree; | ||
| 2 | |||
| 3 | // none/d extends none/b | ||
| 4 | public class SubsubclassAA extends SubclassA { | ||
| 5 | |||
| 6 | protected SubsubclassAA() { | ||
| 7 | // call to none/b.<init>(Ljava/lang/String;)V | ||
| 8 | super("AA"); | ||
| 9 | } | ||
| 10 | |||
| 11 | @Override | ||
| 12 | // a()Ljava/lang/String; | ||
| 13 | public String getName() { | ||
| 14 | // call to none/b.a()Ljava/lang/String; | ||
| 15 | return "subsub" + super.getName(); | ||
| 16 | } | ||
| 17 | |||
| 18 | @Override | ||
| 19 | // a()V | ||
| 20 | public void doBaseThings() { | ||
| 21 | // call to none/d.a()Ljava/lang/String; | ||
| 22 | System.out.println("Base things by " + getName()); | ||
| 23 | } | ||
| 24 | } | ||
diff --git a/test/cuchaz/enigma/inputs/innerClasses/A_Anonymous.java b/test/cuchaz/enigma/inputs/innerClasses/A_Anonymous.java new file mode 100644 index 0000000..f7118f6 --- /dev/null +++ b/test/cuchaz/enigma/inputs/innerClasses/A_Anonymous.java | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | package cuchaz.enigma.inputs.innerClasses; | ||
| 2 | |||
| 3 | public class A_Anonymous { | ||
| 4 | |||
| 5 | public void foo() { | ||
| 6 | Runnable runnable = new Runnable() { | ||
| 7 | @Override | ||
| 8 | public void run() { | ||
| 9 | // don't care | ||
| 10 | } | ||
| 11 | }; | ||
| 12 | runnable.run(); | ||
| 13 | } | ||
| 14 | } | ||
diff --git a/test/cuchaz/enigma/inputs/innerClasses/B_AnonymousWithScopeArgs.java b/test/cuchaz/enigma/inputs/innerClasses/B_AnonymousWithScopeArgs.java new file mode 100644 index 0000000..42fba9a --- /dev/null +++ b/test/cuchaz/enigma/inputs/innerClasses/B_AnonymousWithScopeArgs.java | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | package cuchaz.enigma.inputs.innerClasses; | ||
| 2 | |||
| 3 | public class B_AnonymousWithScopeArgs { | ||
| 4 | |||
| 5 | public static void foo(final D_Simple arg) { | ||
| 6 | System.out.println(new Object() { | ||
| 7 | @Override | ||
| 8 | public String toString() { | ||
| 9 | return arg.toString(); | ||
| 10 | } | ||
| 11 | }); | ||
| 12 | } | ||
| 13 | } | ||
diff --git a/test/cuchaz/enigma/inputs/innerClasses/C_ConstructorArgs.java b/test/cuchaz/enigma/inputs/innerClasses/C_ConstructorArgs.java new file mode 100644 index 0000000..8fa6c5b --- /dev/null +++ b/test/cuchaz/enigma/inputs/innerClasses/C_ConstructorArgs.java | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | package cuchaz.enigma.inputs.innerClasses; | ||
| 2 | |||
| 3 | @SuppressWarnings("unused") | ||
| 4 | public class C_ConstructorArgs { | ||
| 5 | |||
| 6 | class Inner { | ||
| 7 | |||
| 8 | private int a; | ||
| 9 | |||
| 10 | public Inner(int a) { | ||
| 11 | this.a = a; | ||
| 12 | } | ||
| 13 | } | ||
| 14 | |||
| 15 | Inner i; | ||
| 16 | |||
| 17 | public void foo() { | ||
| 18 | i = new Inner(5); | ||
| 19 | } | ||
| 20 | } | ||
diff --git a/test/cuchaz/enigma/inputs/innerClasses/D_Simple.java b/test/cuchaz/enigma/inputs/innerClasses/D_Simple.java new file mode 100644 index 0000000..c4fc0ef --- /dev/null +++ b/test/cuchaz/enigma/inputs/innerClasses/D_Simple.java | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | package cuchaz.enigma.inputs.innerClasses; | ||
| 2 | |||
| 3 | public class D_Simple { | ||
| 4 | |||
| 5 | class Inner { | ||
| 6 | // nothing to do | ||
| 7 | } | ||
| 8 | } | ||
diff --git a/test/cuchaz/enigma/inputs/innerClasses/E_AnonymousWithOuterAccess.java b/test/cuchaz/enigma/inputs/innerClasses/E_AnonymousWithOuterAccess.java new file mode 100644 index 0000000..e1de53c --- /dev/null +++ b/test/cuchaz/enigma/inputs/innerClasses/E_AnonymousWithOuterAccess.java | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | package cuchaz.enigma.inputs.innerClasses; | ||
| 2 | |||
| 3 | public class E_AnonymousWithOuterAccess { | ||
| 4 | |||
| 5 | // reproduction of error case documented at: | ||
| 6 | // https://bitbucket.org/cuchaz/enigma/issue/61/stackoverflowerror-when-deobfuscating | ||
| 7 | |||
| 8 | public Object makeInner() { | ||
| 9 | outerMethod(); | ||
| 10 | return new Object() { | ||
| 11 | @Override | ||
| 12 | public String toString() { | ||
| 13 | return outerMethod(); | ||
| 14 | } | ||
| 15 | }; | ||
| 16 | } | ||
| 17 | |||
| 18 | private String outerMethod() { | ||
| 19 | return "foo"; | ||
| 20 | } | ||
| 21 | } | ||
diff --git a/test/cuchaz/enigma/inputs/loneClass/LoneClass.java b/test/cuchaz/enigma/inputs/loneClass/LoneClass.java new file mode 100644 index 0000000..18c716e --- /dev/null +++ b/test/cuchaz/enigma/inputs/loneClass/LoneClass.java | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | package cuchaz.enigma.inputs.loneClass; | ||
| 2 | |||
| 3 | public class LoneClass { | ||
| 4 | |||
| 5 | private String m_name; | ||
| 6 | |||
| 7 | public LoneClass(String name) { | ||
| 8 | m_name = name; | ||
| 9 | } | ||
| 10 | |||
| 11 | public String getName() { | ||
| 12 | return m_name; | ||
| 13 | } | ||
| 14 | } | ||
diff --git a/test/cuchaz/enigma/inputs/translation/A.java b/test/cuchaz/enigma/inputs/translation/A.java new file mode 100644 index 0000000..b8aaf11 --- /dev/null +++ b/test/cuchaz/enigma/inputs/translation/A.java | |||
| @@ -0,0 +1,8 @@ | |||
| 1 | package cuchaz.enigma.inputs.translation; | ||
| 2 | |||
| 3 | public class A { | ||
| 4 | |||
| 5 | public int one; | ||
| 6 | public float two; | ||
| 7 | public String three; | ||
| 8 | } | ||
diff --git a/test/cuchaz/enigma/resources/translation.mappings b/test/cuchaz/enigma/resources/translation.mappings new file mode 100644 index 0000000..70755bf --- /dev/null +++ b/test/cuchaz/enigma/resources/translation.mappings | |||
| @@ -0,0 +1,4 @@ | |||
| 1 | CLASS none/a deobf/A | ||
| 2 | FIELD a one | ||
| 3 | FIELD b two | ||
| 4 | FIELD c three \ No newline at end of file | ||