diff options
| author | 2016-06-30 00:49:21 +1000 | |
|---|---|---|
| committer | 2016-06-30 00:49:21 +1000 | |
| commit | 4be005617b3b8c3578cca07c5d085d12916f0d1d (patch) | |
| tree | db163431f38703e26da417ef05eaea2b27a498b9 /src/test | |
| parent | Some small changes to fix idea importing (diff) | |
| download | enigma-4be005617b3b8c3578cca07c5d085d12916f0d1d.tar.gz enigma-4be005617b3b8c3578cca07c5d085d12916f0d1d.tar.xz enigma-4be005617b3b8c3578cca07c5d085d12916f0d1d.zip | |
Json format (#2)
* Added new format
* Fixed bug
* Updated Version
Diffstat (limited to 'src/test')
40 files changed, 2630 insertions, 0 deletions
diff --git a/src/test/java/cuchaz/enigma/TestDeobfed.java b/src/test/java/cuchaz/enigma/TestDeobfed.java new file mode 100644 index 00000000..5f3ef8cf --- /dev/null +++ b/src/test/java/cuchaz/enigma/TestDeobfed.java | |||
| @@ -0,0 +1,95 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma; | ||
| 12 | |||
| 13 | |||
| 14 | import static cuchaz.enigma.TestEntryFactory.*; | ||
| 15 | import static org.hamcrest.MatcherAssert.*; | ||
| 16 | import static org.hamcrest.Matchers.*; | ||
| 17 | |||
| 18 | import java.util.jar.JarFile; | ||
| 19 | |||
| 20 | import org.junit.BeforeClass; | ||
| 21 | import org.junit.Test; | ||
| 22 | |||
| 23 | import cuchaz.enigma.analysis.JarIndex; | ||
| 24 | |||
| 25 | |||
| 26 | public class TestDeobfed { | ||
| 27 | |||
| 28 | private static JarFile m_jar; | ||
| 29 | private static JarIndex m_index; | ||
| 30 | |||
| 31 | @BeforeClass | ||
| 32 | public static void beforeClass() | ||
| 33 | throws Exception { | ||
| 34 | m_jar = new JarFile("build/test-deobf/translation.jar"); | ||
| 35 | m_index = new JarIndex(); | ||
| 36 | m_index.indexJar(m_jar, true); | ||
| 37 | } | ||
| 38 | |||
| 39 | @Test | ||
| 40 | public void obfEntries() { | ||
| 41 | assertThat(m_index.getObfClassEntries(), containsInAnyOrder( | ||
| 42 | newClass("cuchaz/enigma/inputs/Keep"), | ||
| 43 | newClass("none/a"), | ||
| 44 | newClass("none/b"), | ||
| 45 | newClass("none/c"), | ||
| 46 | newClass("none/d"), | ||
| 47 | newClass("none/d$1"), | ||
| 48 | newClass("none/e"), | ||
| 49 | newClass("none/f"), | ||
| 50 | newClass("none/g"), | ||
| 51 | newClass("none/g$a"), | ||
| 52 | newClass("none/g$a$a"), | ||
| 53 | newClass("none/g$b"), | ||
| 54 | newClass("none/g$b$a"), | ||
| 55 | newClass("none/h"), | ||
| 56 | newClass("none/h$a"), | ||
| 57 | newClass("none/h$a$a"), | ||
| 58 | newClass("none/h$b"), | ||
| 59 | newClass("none/h$b$a"), | ||
| 60 | newClass("none/h$b$a$a"), | ||
| 61 | newClass("none/h$b$a$b"), | ||
| 62 | newClass("none/i"), | ||
| 63 | newClass("none/i$a"), | ||
| 64 | newClass("none/i$b") | ||
| 65 | )); | ||
| 66 | } | ||
| 67 | |||
| 68 | @Test | ||
| 69 | public void decompile() | ||
| 70 | throws Exception { | ||
| 71 | Deobfuscator deobfuscator = new Deobfuscator(m_jar); | ||
| 72 | deobfuscator.getSourceTree("none/a"); | ||
| 73 | deobfuscator.getSourceTree("none/b"); | ||
| 74 | deobfuscator.getSourceTree("none/c"); | ||
| 75 | deobfuscator.getSourceTree("none/d"); | ||
| 76 | deobfuscator.getSourceTree("none/d$1"); | ||
| 77 | deobfuscator.getSourceTree("none/e"); | ||
| 78 | deobfuscator.getSourceTree("none/f"); | ||
| 79 | deobfuscator.getSourceTree("none/g"); | ||
| 80 | deobfuscator.getSourceTree("none/g$a"); | ||
| 81 | deobfuscator.getSourceTree("none/g$a$a"); | ||
| 82 | deobfuscator.getSourceTree("none/g$b"); | ||
| 83 | deobfuscator.getSourceTree("none/g$b$a"); | ||
| 84 | deobfuscator.getSourceTree("none/h"); | ||
| 85 | deobfuscator.getSourceTree("none/h$a"); | ||
| 86 | deobfuscator.getSourceTree("none/h$a$a"); | ||
| 87 | deobfuscator.getSourceTree("none/h$b"); | ||
| 88 | deobfuscator.getSourceTree("none/h$b$a"); | ||
| 89 | deobfuscator.getSourceTree("none/h$b$a$a"); | ||
| 90 | deobfuscator.getSourceTree("none/h$b$a$b"); | ||
| 91 | deobfuscator.getSourceTree("none/i"); | ||
| 92 | deobfuscator.getSourceTree("none/i$a"); | ||
| 93 | deobfuscator.getSourceTree("none/i$b"); | ||
| 94 | } | ||
| 95 | } | ||
diff --git a/src/test/java/cuchaz/enigma/TestDeobfuscator.java b/src/test/java/cuchaz/enigma/TestDeobfuscator.java new file mode 100644 index 00000000..1b0aa74d --- /dev/null +++ b/src/test/java/cuchaz/enigma/TestDeobfuscator.java | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma; | ||
| 12 | |||
| 13 | import static org.junit.Assert.*; | ||
| 14 | |||
| 15 | import java.io.IOException; | ||
| 16 | import java.util.List; | ||
| 17 | import java.util.jar.JarFile; | ||
| 18 | |||
| 19 | import org.junit.Test; | ||
| 20 | |||
| 21 | import com.google.common.collect.Lists; | ||
| 22 | |||
| 23 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 24 | |||
| 25 | public class TestDeobfuscator { | ||
| 26 | |||
| 27 | private Deobfuscator getDeobfuscator() | ||
| 28 | throws IOException { | ||
| 29 | return new Deobfuscator(new JarFile("build/test-obf/loneClass.jar")); | ||
| 30 | } | ||
| 31 | |||
| 32 | @Test | ||
| 33 | public void loadJar() | ||
| 34 | throws Exception { | ||
| 35 | getDeobfuscator(); | ||
| 36 | } | ||
| 37 | |||
| 38 | @Test | ||
| 39 | public void getClasses() | ||
| 40 | throws Exception { | ||
| 41 | Deobfuscator deobfuscator = getDeobfuscator(); | ||
| 42 | List<ClassEntry> obfClasses = Lists.newArrayList(); | ||
| 43 | List<ClassEntry> deobfClasses = Lists.newArrayList(); | ||
| 44 | deobfuscator.getSeparatedClasses(obfClasses, deobfClasses); | ||
| 45 | assertEquals(1, obfClasses.size()); | ||
| 46 | assertEquals("none/a", obfClasses.get(0).getName()); | ||
| 47 | assertEquals(1, deobfClasses.size()); | ||
| 48 | assertEquals("cuchaz/enigma/inputs/Keep", deobfClasses.get(0).getName()); | ||
| 49 | } | ||
| 50 | |||
| 51 | @Test | ||
| 52 | public void decompileClass() | ||
| 53 | throws Exception { | ||
| 54 | Deobfuscator deobfuscator = getDeobfuscator(); | ||
| 55 | deobfuscator.getSource(deobfuscator.getSourceTree("none/a")); | ||
| 56 | } | ||
| 57 | } | ||
diff --git a/src/test/java/cuchaz/enigma/TestEntryFactory.java b/src/test/java/cuchaz/enigma/TestEntryFactory.java new file mode 100644 index 00000000..4aa773b6 --- /dev/null +++ b/src/test/java/cuchaz/enigma/TestEntryFactory.java | |||
| @@ -0,0 +1,67 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma; | ||
| 12 | |||
| 13 | import cuchaz.enigma.analysis.EntryReference; | ||
| 14 | import cuchaz.enigma.mapping.BehaviorEntry; | ||
| 15 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 16 | import cuchaz.enigma.mapping.ConstructorEntry; | ||
| 17 | import cuchaz.enigma.mapping.FieldEntry; | ||
| 18 | import cuchaz.enigma.mapping.MethodEntry; | ||
| 19 | import cuchaz.enigma.mapping.Signature; | ||
| 20 | import cuchaz.enigma.mapping.Type; | ||
| 21 | |||
| 22 | public class TestEntryFactory { | ||
| 23 | |||
| 24 | public static ClassEntry newClass(String name) { | ||
| 25 | return new ClassEntry(name); | ||
| 26 | } | ||
| 27 | |||
| 28 | public static FieldEntry newField(String className, String fieldName, String fieldType) { | ||
| 29 | return newField(newClass(className), fieldName, fieldType); | ||
| 30 | } | ||
| 31 | |||
| 32 | public static FieldEntry newField(ClassEntry classEntry, String fieldName, String fieldType) { | ||
| 33 | return new FieldEntry(classEntry, fieldName, new Type(fieldType)); | ||
| 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/src/test/java/cuchaz/enigma/TestInnerClasses.java b/src/test/java/cuchaz/enigma/TestInnerClasses.java new file mode 100644 index 00000000..a4f90217 --- /dev/null +++ b/src/test/java/cuchaz/enigma/TestInnerClasses.java | |||
| @@ -0,0 +1,132 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma; | ||
| 12 | |||
| 13 | import static org.hamcrest.MatcherAssert.*; | ||
| 14 | import static org.hamcrest.Matchers.*; | ||
| 15 | |||
| 16 | import java.util.jar.JarFile; | ||
| 17 | |||
| 18 | import org.junit.Test; | ||
| 19 | |||
| 20 | import static cuchaz.enigma.TestEntryFactory.*; | ||
| 21 | |||
| 22 | import cuchaz.enigma.analysis.JarIndex; | ||
| 23 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 24 | |||
| 25 | public class TestInnerClasses { | ||
| 26 | |||
| 27 | private JarIndex m_index; | ||
| 28 | private Deobfuscator m_deobfuscator; | ||
| 29 | |||
| 30 | private static final ClassEntry AnonymousOuter = newClass("none/a"); | ||
| 31 | private static final ClassEntry AnonymousInner = newClass("none/a$1"); | ||
| 32 | private static final ClassEntry SimpleOuter = newClass("none/d"); | ||
| 33 | private static final ClassEntry SimpleInner = newClass("none/d$a"); | ||
| 34 | private static final ClassEntry ConstructorArgsOuter = newClass("none/c"); | ||
| 35 | private static final ClassEntry ConstructorArgsInner = newClass("none/c$a"); | ||
| 36 | private static final ClassEntry AnonymousWithScopeArgsOuter = newClass("none/b"); | ||
| 37 | private static final ClassEntry AnonymousWithScopeArgsInner = newClass("none/b$1"); | ||
| 38 | private static final ClassEntry AnonymousWithOuterAccessOuter = newClass("none/e"); | ||
| 39 | private static final ClassEntry AnonymousWithOuterAccessInner = newClass("none/e$1"); | ||
| 40 | private static final ClassEntry ClassTreeRoot = newClass("none/f"); | ||
| 41 | private static final ClassEntry ClassTreeLevel1 = newClass("none/f$a"); | ||
| 42 | private static final ClassEntry ClassTreeLevel2 = newClass("none/f$a$a"); | ||
| 43 | private static final ClassEntry ClassTreeLevel3 = newClass("none/f$a$a$a"); | ||
| 44 | |||
| 45 | public TestInnerClasses() | ||
| 46 | throws Exception { | ||
| 47 | m_index = new JarIndex(); | ||
| 48 | JarFile jar = new JarFile("build/test-obf/innerClasses.jar"); | ||
| 49 | m_index.indexJar(jar, true); | ||
| 50 | m_deobfuscator = new Deobfuscator(jar); | ||
| 51 | } | ||
| 52 | |||
| 53 | @Test | ||
| 54 | public void simple() { | ||
| 55 | assertThat(m_index.getOuterClass(SimpleInner), is(SimpleOuter)); | ||
| 56 | assertThat(m_index.getInnerClasses(SimpleOuter), containsInAnyOrder(SimpleInner)); | ||
| 57 | assertThat(m_index.isAnonymousClass(SimpleInner), is(false)); | ||
| 58 | decompile(SimpleOuter); | ||
| 59 | } | ||
| 60 | |||
| 61 | @Test | ||
| 62 | public void anonymous() { | ||
| 63 | assertThat(m_index.getOuterClass(AnonymousInner), is(AnonymousOuter)); | ||
| 64 | assertThat(m_index.getInnerClasses(AnonymousOuter), containsInAnyOrder(AnonymousInner)); | ||
| 65 | assertThat(m_index.isAnonymousClass(AnonymousInner), is(true)); | ||
| 66 | decompile(AnonymousOuter); | ||
| 67 | } | ||
| 68 | |||
| 69 | @Test | ||
| 70 | public void constructorArgs() { | ||
| 71 | assertThat(m_index.getOuterClass(ConstructorArgsInner), is(ConstructorArgsOuter)); | ||
| 72 | assertThat(m_index.getInnerClasses(ConstructorArgsOuter), containsInAnyOrder(ConstructorArgsInner)); | ||
| 73 | assertThat(m_index.isAnonymousClass(ConstructorArgsInner), is(false)); | ||
| 74 | decompile(ConstructorArgsOuter); | ||
| 75 | } | ||
| 76 | |||
| 77 | @Test | ||
| 78 | public void anonymousWithScopeArgs() { | ||
| 79 | assertThat(m_index.getOuterClass(AnonymousWithScopeArgsInner), is(AnonymousWithScopeArgsOuter)); | ||
| 80 | assertThat(m_index.getInnerClasses(AnonymousWithScopeArgsOuter), containsInAnyOrder(AnonymousWithScopeArgsInner)); | ||
| 81 | assertThat(m_index.isAnonymousClass(AnonymousWithScopeArgsInner), is(true)); | ||
| 82 | decompile(AnonymousWithScopeArgsOuter); | ||
| 83 | } | ||
| 84 | |||
| 85 | @Test | ||
| 86 | public void anonymousWithOuterAccess() { | ||
| 87 | assertThat(m_index.getOuterClass(AnonymousWithOuterAccessInner), is(AnonymousWithOuterAccessOuter)); | ||
| 88 | assertThat(m_index.getInnerClasses(AnonymousWithOuterAccessOuter), containsInAnyOrder(AnonymousWithOuterAccessInner)); | ||
| 89 | assertThat(m_index.isAnonymousClass(AnonymousWithOuterAccessInner), is(true)); | ||
| 90 | decompile(AnonymousWithOuterAccessOuter); | ||
| 91 | } | ||
| 92 | |||
| 93 | @Test | ||
| 94 | public void classTree() { | ||
| 95 | |||
| 96 | // root level | ||
| 97 | assertThat(m_index.containsObfClass(ClassTreeRoot), is(true)); | ||
| 98 | assertThat(m_index.getOuterClass(ClassTreeRoot), is(nullValue())); | ||
| 99 | assertThat(m_index.getInnerClasses(ClassTreeRoot), containsInAnyOrder(ClassTreeLevel1)); | ||
| 100 | |||
| 101 | // level 1 | ||
| 102 | ClassEntry fullClassEntry = new ClassEntry(ClassTreeRoot.getName() | ||
| 103 | + "$" + ClassTreeLevel1.getInnermostClassName() | ||
| 104 | ); | ||
| 105 | assertThat(m_index.containsObfClass(fullClassEntry), is(true)); | ||
| 106 | assertThat(m_index.getOuterClass(ClassTreeLevel1), is(ClassTreeRoot)); | ||
| 107 | assertThat(m_index.getInnerClasses(ClassTreeLevel1), containsInAnyOrder(ClassTreeLevel2)); | ||
| 108 | |||
| 109 | // level 2 | ||
| 110 | fullClassEntry = new ClassEntry(ClassTreeRoot.getName() | ||
| 111 | + "$" + ClassTreeLevel1.getInnermostClassName() | ||
| 112 | + "$" + ClassTreeLevel2.getInnermostClassName() | ||
| 113 | ); | ||
| 114 | assertThat(m_index.containsObfClass(fullClassEntry), is(true)); | ||
| 115 | assertThat(m_index.getOuterClass(ClassTreeLevel2), is(ClassTreeLevel1)); | ||
| 116 | assertThat(m_index.getInnerClasses(ClassTreeLevel2), containsInAnyOrder(ClassTreeLevel3)); | ||
| 117 | |||
| 118 | // level 3 | ||
| 119 | fullClassEntry = new ClassEntry(ClassTreeRoot.getName() | ||
| 120 | + "$" + ClassTreeLevel1.getInnermostClassName() | ||
| 121 | + "$" + ClassTreeLevel2.getInnermostClassName() | ||
| 122 | + "$" + ClassTreeLevel3.getInnermostClassName() | ||
| 123 | ); | ||
| 124 | assertThat(m_index.containsObfClass(fullClassEntry), is(true)); | ||
| 125 | assertThat(m_index.getOuterClass(ClassTreeLevel3), is(ClassTreeLevel2)); | ||
| 126 | assertThat(m_index.getInnerClasses(ClassTreeLevel3), is(empty())); | ||
| 127 | } | ||
| 128 | |||
| 129 | private void decompile(ClassEntry classEntry) { | ||
| 130 | m_deobfuscator.getSourceTree(classEntry.getName()); | ||
| 131 | } | ||
| 132 | } | ||
diff --git a/src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java b/src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java new file mode 100644 index 00000000..606801bd --- /dev/null +++ b/src/test/java/cuchaz/enigma/TestJarIndexConstructorReferences.java | |||
| @@ -0,0 +1,124 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma; | ||
| 12 | |||
| 13 | import static cuchaz.enigma.TestEntryFactory.*; | ||
| 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/test-obf/constructors.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/src/test/java/cuchaz/enigma/TestJarIndexInheritanceTree.java b/src/test/java/cuchaz/enigma/TestJarIndexInheritanceTree.java new file mode 100644 index 00000000..84d21158 --- /dev/null +++ b/src/test/java/cuchaz/enigma/TestJarIndexInheritanceTree.java | |||
| @@ -0,0 +1,239 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma; | ||
| 12 | |||
| 13 | import static cuchaz.enigma.TestEntryFactory.newBehaviorReferenceByConstructor; | ||
| 14 | import static cuchaz.enigma.TestEntryFactory.newBehaviorReferenceByMethod; | ||
| 15 | import static cuchaz.enigma.TestEntryFactory.newClass; | ||
| 16 | import static cuchaz.enigma.TestEntryFactory.newConstructor; | ||
| 17 | import static cuchaz.enigma.TestEntryFactory.newField; | ||
| 18 | import static cuchaz.enigma.TestEntryFactory.newFieldReferenceByConstructor; | ||
| 19 | import static cuchaz.enigma.TestEntryFactory.newFieldReferenceByMethod; | ||
| 20 | import static cuchaz.enigma.TestEntryFactory.newMethod; | ||
| 21 | import static org.hamcrest.MatcherAssert.assertThat; | ||
| 22 | import static org.hamcrest.Matchers.contains; | ||
| 23 | import static org.hamcrest.Matchers.containsInAnyOrder; | ||
| 24 | import static org.hamcrest.Matchers.empty; | ||
| 25 | import static org.hamcrest.Matchers.is; | ||
| 26 | |||
| 27 | import java.util.Collection; | ||
| 28 | import java.util.Set; | ||
| 29 | import java.util.jar.JarFile; | ||
| 30 | |||
| 31 | import org.junit.Test; | ||
| 32 | |||
| 33 | import cuchaz.enigma.analysis.Access; | ||
| 34 | import cuchaz.enigma.analysis.EntryReference; | ||
| 35 | import cuchaz.enigma.analysis.JarIndex; | ||
| 36 | import cuchaz.enigma.analysis.TranslationIndex; | ||
| 37 | import cuchaz.enigma.mapping.BehaviorEntry; | ||
| 38 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 39 | import cuchaz.enigma.mapping.FieldEntry; | ||
| 40 | import cuchaz.enigma.mapping.MethodEntry; | ||
| 41 | |||
| 42 | public class TestJarIndexInheritanceTree { | ||
| 43 | |||
| 44 | private JarIndex m_index; | ||
| 45 | |||
| 46 | private ClassEntry m_objectClass = newClass("java/lang/Object"); | ||
| 47 | private ClassEntry m_baseClass = newClass("none/a"); | ||
| 48 | private ClassEntry m_subClassA = newClass("none/b"); | ||
| 49 | private ClassEntry m_subClassAA = newClass("none/d"); | ||
| 50 | private ClassEntry m_subClassB = newClass("none/c"); | ||
| 51 | private FieldEntry m_nameField = newField(m_baseClass, "a", "Ljava/lang/String;"); | ||
| 52 | private FieldEntry m_numThingsField = newField(m_subClassB, "a", "I"); | ||
| 53 | |||
| 54 | public TestJarIndexInheritanceTree() | ||
| 55 | throws Exception { | ||
| 56 | m_index = new JarIndex(); | ||
| 57 | m_index.indexJar(new JarFile("build/test-obf/inheritanceTree.jar"), false); | ||
| 58 | } | ||
| 59 | |||
| 60 | @Test | ||
| 61 | public void obfEntries() { | ||
| 62 | assertThat(m_index.getObfClassEntries(), containsInAnyOrder( | ||
| 63 | newClass("cuchaz/enigma/inputs/Keep"), | ||
| 64 | m_baseClass, | ||
| 65 | m_subClassA, | ||
| 66 | m_subClassAA, | ||
| 67 | m_subClassB | ||
| 68 | )); | ||
| 69 | } | ||
| 70 | |||
| 71 | @Test | ||
| 72 | public void translationIndex() { | ||
| 73 | |||
| 74 | TranslationIndex index = m_index.getTranslationIndex(); | ||
| 75 | |||
| 76 | // base class | ||
| 77 | assertThat(index.getSuperclass(m_baseClass), is(m_objectClass)); | ||
| 78 | assertThat(index.getAncestry(m_baseClass), contains(m_objectClass)); | ||
| 79 | assertThat(index.getSubclass(m_baseClass), containsInAnyOrder( | ||
| 80 | m_subClassA, | ||
| 81 | m_subClassB | ||
| 82 | )); | ||
| 83 | |||
| 84 | // subclass a | ||
| 85 | assertThat(index.getSuperclass(m_subClassA), is(m_baseClass)); | ||
| 86 | assertThat(index.getAncestry(m_subClassA), contains(m_baseClass, m_objectClass)); | ||
| 87 | assertThat(index.getSubclass(m_subClassA), contains(m_subClassAA)); | ||
| 88 | |||
| 89 | // subclass aa | ||
| 90 | assertThat(index.getSuperclass(m_subClassAA), is(m_subClassA)); | ||
| 91 | assertThat(index.getAncestry(m_subClassAA), contains(m_subClassA, m_baseClass, m_objectClass)); | ||
| 92 | assertThat(index.getSubclass(m_subClassAA), is(empty())); | ||
| 93 | |||
| 94 | // subclass b | ||
| 95 | assertThat(index.getSuperclass(m_subClassB), is(m_baseClass)); | ||
| 96 | assertThat(index.getAncestry(m_subClassB), contains(m_baseClass, m_objectClass)); | ||
| 97 | assertThat(index.getSubclass(m_subClassB), is(empty())); | ||
| 98 | } | ||
| 99 | |||
| 100 | @Test | ||
| 101 | public void access() { | ||
| 102 | assertThat(m_index.getAccess(m_nameField), is(Access.Private)); | ||
| 103 | assertThat(m_index.getAccess(m_numThingsField), is(Access.Private)); | ||
| 104 | } | ||
| 105 | |||
| 106 | @Test | ||
| 107 | public void relatedMethodImplementations() { | ||
| 108 | |||
| 109 | Set<MethodEntry> entries; | ||
| 110 | |||
| 111 | // getName() | ||
| 112 | entries = m_index.getRelatedMethodImplementations(newMethod(m_baseClass, "a", "()Ljava/lang/String;")); | ||
| 113 | assertThat(entries, containsInAnyOrder( | ||
| 114 | newMethod(m_baseClass, "a", "()Ljava/lang/String;"), | ||
| 115 | newMethod(m_subClassAA, "a", "()Ljava/lang/String;") | ||
| 116 | )); | ||
| 117 | entries = m_index.getRelatedMethodImplementations(newMethod(m_subClassAA, "a", "()Ljava/lang/String;")); | ||
| 118 | assertThat(entries, containsInAnyOrder( | ||
| 119 | newMethod(m_baseClass, "a", "()Ljava/lang/String;"), | ||
| 120 | newMethod(m_subClassAA, "a", "()Ljava/lang/String;") | ||
| 121 | )); | ||
| 122 | |||
| 123 | // doBaseThings() | ||
| 124 | entries = m_index.getRelatedMethodImplementations(newMethod(m_baseClass, "a", "()V")); | ||
| 125 | assertThat(entries, containsInAnyOrder( | ||
| 126 | newMethod(m_baseClass, "a", "()V"), | ||
| 127 | newMethod(m_subClassAA, "a", "()V"), | ||
| 128 | newMethod(m_subClassB, "a", "()V") | ||
| 129 | )); | ||
| 130 | entries = m_index.getRelatedMethodImplementations(newMethod(m_subClassAA, "a", "()V")); | ||
| 131 | assertThat(entries, containsInAnyOrder( | ||
| 132 | newMethod(m_baseClass, "a", "()V"), | ||
| 133 | newMethod(m_subClassAA, "a", "()V"), | ||
| 134 | newMethod(m_subClassB, "a", "()V") | ||
| 135 | )); | ||
| 136 | entries = m_index.getRelatedMethodImplementations(newMethod(m_subClassB, "a", "()V")); | ||
| 137 | assertThat(entries, containsInAnyOrder( | ||
| 138 | newMethod(m_baseClass, "a", "()V"), | ||
| 139 | newMethod(m_subClassAA, "a", "()V"), | ||
| 140 | newMethod(m_subClassB, "a", "()V") | ||
| 141 | )); | ||
| 142 | |||
| 143 | // doBThings | ||
| 144 | entries = m_index.getRelatedMethodImplementations(newMethod(m_subClassB, "b", "()V")); | ||
| 145 | assertThat(entries, containsInAnyOrder(newMethod(m_subClassB, "b", "()V"))); | ||
| 146 | } | ||
| 147 | |||
| 148 | @Test | ||
| 149 | @SuppressWarnings("unchecked") | ||
| 150 | public void fieldReferences() { | ||
| 151 | Collection<EntryReference<FieldEntry,BehaviorEntry>> references; | ||
| 152 | |||
| 153 | // name | ||
| 154 | references = m_index.getFieldReferences(m_nameField); | ||
| 155 | assertThat(references, containsInAnyOrder( | ||
| 156 | newFieldReferenceByConstructor(m_nameField, m_baseClass.getName(), "(Ljava/lang/String;)V"), | ||
| 157 | newFieldReferenceByMethod(m_nameField, m_baseClass.getName(), "a", "()Ljava/lang/String;") | ||
| 158 | )); | ||
| 159 | |||
| 160 | // numThings | ||
| 161 | references = m_index.getFieldReferences(m_numThingsField); | ||
| 162 | assertThat(references, containsInAnyOrder( | ||
| 163 | newFieldReferenceByConstructor(m_numThingsField, m_subClassB.getName(), "()V"), | ||
| 164 | newFieldReferenceByMethod(m_numThingsField, m_subClassB.getName(), "b", "()V") | ||
| 165 | )); | ||
| 166 | } | ||
| 167 | |||
| 168 | @Test | ||
| 169 | @SuppressWarnings("unchecked") | ||
| 170 | public void behaviorReferences() { | ||
| 171 | |||
| 172 | BehaviorEntry source; | ||
| 173 | Collection<EntryReference<BehaviorEntry,BehaviorEntry>> references; | ||
| 174 | |||
| 175 | // baseClass constructor | ||
| 176 | source = newConstructor(m_baseClass, "(Ljava/lang/String;)V"); | ||
| 177 | references = m_index.getBehaviorReferences(source); | ||
| 178 | assertThat(references, containsInAnyOrder( | ||
| 179 | newBehaviorReferenceByConstructor(source, m_subClassA.getName(), "(Ljava/lang/String;)V"), | ||
| 180 | newBehaviorReferenceByConstructor(source, m_subClassB.getName(), "()V") | ||
| 181 | )); | ||
| 182 | |||
| 183 | // subClassA constructor | ||
| 184 | source = newConstructor(m_subClassA, "(Ljava/lang/String;)V"); | ||
| 185 | references = m_index.getBehaviorReferences(source); | ||
| 186 | assertThat(references, containsInAnyOrder( | ||
| 187 | newBehaviorReferenceByConstructor(source, m_subClassAA.getName(), "()V") | ||
| 188 | )); | ||
| 189 | |||
| 190 | // baseClass.getName() | ||
| 191 | source = newMethod(m_baseClass, "a", "()Ljava/lang/String;"); | ||
| 192 | references = m_index.getBehaviorReferences(source); | ||
| 193 | assertThat(references, containsInAnyOrder( | ||
| 194 | newBehaviorReferenceByMethod(source, m_subClassAA.getName(), "a", "()Ljava/lang/String;"), | ||
| 195 | newBehaviorReferenceByMethod(source, m_subClassB.getName(), "a", "()V") | ||
| 196 | )); | ||
| 197 | |||
| 198 | // subclassAA.getName() | ||
| 199 | source = newMethod(m_subClassAA, "a", "()Ljava/lang/String;"); | ||
| 200 | references = m_index.getBehaviorReferences(source); | ||
| 201 | assertThat(references, containsInAnyOrder( | ||
| 202 | newBehaviorReferenceByMethod(source, m_subClassAA.getName(), "a", "()V") | ||
| 203 | )); | ||
| 204 | } | ||
| 205 | |||
| 206 | @Test | ||
| 207 | public void containsEntries() { | ||
| 208 | |||
| 209 | // classes | ||
| 210 | assertThat(m_index.containsObfClass(m_baseClass), is(true)); | ||
| 211 | assertThat(m_index.containsObfClass(m_subClassA), is(true)); | ||
| 212 | assertThat(m_index.containsObfClass(m_subClassAA), is(true)); | ||
| 213 | assertThat(m_index.containsObfClass(m_subClassB), is(true)); | ||
| 214 | |||
| 215 | // fields | ||
| 216 | assertThat(m_index.containsObfField(m_nameField), is(true)); | ||
| 217 | assertThat(m_index.containsObfField(m_numThingsField), is(true)); | ||
| 218 | |||
| 219 | // methods | ||
| 220 | // getName() | ||
| 221 | assertThat(m_index.containsObfBehavior(newMethod(m_baseClass, "a", "()Ljava/lang/String;")), is(true)); | ||
| 222 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassA, "a", "()Ljava/lang/String;")), is(false)); | ||
| 223 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassAA, "a", "()Ljava/lang/String;")), is(true)); | ||
| 224 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassB, "a", "()Ljava/lang/String;")), is(false)); | ||
| 225 | |||
| 226 | // doBaseThings() | ||
| 227 | assertThat(m_index.containsObfBehavior(newMethod(m_baseClass, "a", "()V")), is(true)); | ||
| 228 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassA, "a", "()V")), is(false)); | ||
| 229 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassAA, "a", "()V")), is(true)); | ||
| 230 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassB, "a", "()V")), is(true)); | ||
| 231 | |||
| 232 | // doBThings() | ||
| 233 | assertThat(m_index.containsObfBehavior(newMethod(m_baseClass, "b", "()V")), is(false)); | ||
| 234 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassA, "b", "()V")), is(false)); | ||
| 235 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassAA, "b", "()V")), is(false)); | ||
| 236 | assertThat(m_index.containsObfBehavior(newMethod(m_subClassB, "b", "()V")), is(true)); | ||
| 237 | |||
| 238 | } | ||
| 239 | } | ||
diff --git a/src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java b/src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java new file mode 100644 index 00000000..bd7b03a0 --- /dev/null +++ b/src/test/java/cuchaz/enigma/TestJarIndexLoneClass.java | |||
| @@ -0,0 +1,164 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma; | ||
| 12 | |||
| 13 | import static cuchaz.enigma.TestEntryFactory.*; | ||
| 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.ClassImplementationsTreeNode; | ||
| 25 | import cuchaz.enigma.analysis.ClassInheritanceTreeNode; | ||
| 26 | import cuchaz.enigma.analysis.EntryReference; | ||
| 27 | import cuchaz.enigma.analysis.JarIndex; | ||
| 28 | import cuchaz.enigma.analysis.MethodInheritanceTreeNode; | ||
| 29 | import cuchaz.enigma.mapping.BehaviorEntry; | ||
| 30 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 31 | import cuchaz.enigma.mapping.FieldEntry; | ||
| 32 | import cuchaz.enigma.mapping.MethodEntry; | ||
| 33 | import cuchaz.enigma.mapping.Translator; | ||
| 34 | |||
| 35 | public class TestJarIndexLoneClass { | ||
| 36 | |||
| 37 | private JarIndex m_index; | ||
| 38 | |||
| 39 | public TestJarIndexLoneClass() | ||
| 40 | throws Exception { | ||
| 41 | m_index = new JarIndex(); | ||
| 42 | m_index.indexJar(new JarFile("build/test-obf/loneClass.jar"), false); | ||
| 43 | } | ||
| 44 | |||
| 45 | @Test | ||
| 46 | public void obfEntries() { | ||
| 47 | assertThat(m_index.getObfClassEntries(), containsInAnyOrder( | ||
| 48 | newClass("cuchaz/enigma/inputs/Keep"), | ||
| 49 | newClass("none/a") | ||
| 50 | )); | ||
| 51 | } | ||
| 52 | |||
| 53 | @Test | ||
| 54 | public void translationIndex() { | ||
| 55 | assertThat(m_index.getTranslationIndex().getSuperclass(new ClassEntry("none/a")), is(new ClassEntry("java/lang/Object"))); | ||
| 56 | assertThat(m_index.getTranslationIndex().getSuperclass(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(new ClassEntry("java/lang/Object"))); | ||
| 57 | assertThat(m_index.getTranslationIndex().getAncestry(new ClassEntry("none/a")), contains(new ClassEntry("java/lang/Object"))); | ||
| 58 | assertThat(m_index.getTranslationIndex().getAncestry(new ClassEntry("cuchaz/enigma/inputs/Keep")), contains(new ClassEntry("java/lang/Object"))); | ||
| 59 | assertThat(m_index.getTranslationIndex().getSubclass(new ClassEntry("none/a")), is(empty())); | ||
| 60 | assertThat(m_index.getTranslationIndex().getSubclass(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(empty())); | ||
| 61 | } | ||
| 62 | |||
| 63 | @Test | ||
| 64 | public void access() { | ||
| 65 | assertThat(m_index.getAccess(newField("none/a", "a", "Ljava/lang/String;")), is(Access.Private)); | ||
| 66 | assertThat(m_index.getAccess(newMethod("none/a", "a", "()Ljava/lang/String;")), is(Access.Public)); | ||
| 67 | assertThat(m_index.getAccess(newField("none/a", "b", "Ljava/lang/String;")), is(nullValue())); | ||
| 68 | assertThat(m_index.getAccess(newField("none/a", "a", "LFoo;")), is(nullValue())); | ||
| 69 | } | ||
| 70 | |||
| 71 | @Test | ||
| 72 | public void classInheritance() { | ||
| 73 | ClassInheritanceTreeNode node = m_index.getClassInheritance(new Translator(), newClass("none/a")); | ||
| 74 | assertThat(node, is(not(nullValue()))); | ||
| 75 | assertThat(node.getObfClassName(), is("none/a")); | ||
| 76 | assertThat(node.getChildCount(), is(0)); | ||
| 77 | } | ||
| 78 | |||
| 79 | @Test | ||
| 80 | public void methodInheritance() { | ||
| 81 | MethodEntry source = newMethod("none/a", "a", "()Ljava/lang/String;"); | ||
| 82 | MethodInheritanceTreeNode node = m_index.getMethodInheritance(new Translator(), source); | ||
| 83 | assertThat(node, is(not(nullValue()))); | ||
| 84 | assertThat(node.getMethodEntry(), is(source)); | ||
| 85 | assertThat(node.getChildCount(), is(0)); | ||
| 86 | } | ||
| 87 | |||
| 88 | @Test | ||
| 89 | public void classImplementations() { | ||
| 90 | ClassImplementationsTreeNode node = m_index.getClassImplementations(new Translator(), newClass("none/a")); | ||
| 91 | assertThat(node, is(nullValue())); | ||
| 92 | } | ||
| 93 | |||
| 94 | @Test | ||
| 95 | public void methodImplementations() { | ||
| 96 | MethodEntry source = newMethod("none/a", "a", "()Ljava/lang/String;"); | ||
| 97 | assertThat(m_index.getMethodImplementations(new Translator(), source), is(empty())); | ||
| 98 | } | ||
| 99 | |||
| 100 | @Test | ||
| 101 | public void relatedMethodImplementations() { | ||
| 102 | Set<MethodEntry> entries = m_index.getRelatedMethodImplementations(newMethod("none/a", "a", "()Ljava/lang/String;")); | ||
| 103 | assertThat(entries, containsInAnyOrder( | ||
| 104 | newMethod("none/a", "a", "()Ljava/lang/String;") | ||
| 105 | )); | ||
| 106 | } | ||
| 107 | |||
| 108 | @Test | ||
| 109 | @SuppressWarnings("unchecked") | ||
| 110 | public void fieldReferences() { | ||
| 111 | FieldEntry source = newField("none/a", "a", "Ljava/lang/String;"); | ||
| 112 | Collection<EntryReference<FieldEntry,BehaviorEntry>> references = m_index.getFieldReferences(source); | ||
| 113 | assertThat(references, containsInAnyOrder( | ||
| 114 | newFieldReferenceByConstructor(source, "none/a", "(Ljava/lang/String;)V"), | ||
| 115 | newFieldReferenceByMethod(source, "none/a", "a", "()Ljava/lang/String;") | ||
| 116 | )); | ||
| 117 | } | ||
| 118 | |||
| 119 | @Test | ||
| 120 | public void behaviorReferences() { | ||
| 121 | assertThat(m_index.getBehaviorReferences(newMethod("none/a", "a", "()Ljava/lang/String;")), is(empty())); | ||
| 122 | } | ||
| 123 | |||
| 124 | @Test | ||
| 125 | public void innerClasses() { | ||
| 126 | assertThat(m_index.getInnerClasses(newClass("none/a")), is(empty())); | ||
| 127 | } | ||
| 128 | |||
| 129 | @Test | ||
| 130 | public void outerClass() { | ||
| 131 | assertThat(m_index.getOuterClass(newClass("a")), is(nullValue())); | ||
| 132 | } | ||
| 133 | |||
| 134 | @Test | ||
| 135 | public void isAnonymousClass() { | ||
| 136 | assertThat(m_index.isAnonymousClass(newClass("none/a")), is(false)); | ||
| 137 | } | ||
| 138 | |||
| 139 | @Test | ||
| 140 | public void interfaces() { | ||
| 141 | assertThat(m_index.getInterfaces("none/a"), is(empty())); | ||
| 142 | } | ||
| 143 | |||
| 144 | @Test | ||
| 145 | public void implementingClasses() { | ||
| 146 | assertThat(m_index.getImplementingClasses("none/a"), is(empty())); | ||
| 147 | } | ||
| 148 | |||
| 149 | @Test | ||
| 150 | public void isInterface() { | ||
| 151 | assertThat(m_index.isInterface("none/a"), is(false)); | ||
| 152 | } | ||
| 153 | |||
| 154 | @Test | ||
| 155 | public void testContains() { | ||
| 156 | assertThat(m_index.containsObfClass(newClass("none/a")), is(true)); | ||
| 157 | assertThat(m_index.containsObfClass(newClass("none/b")), is(false)); | ||
| 158 | assertThat(m_index.containsObfField(newField("none/a", "a", "Ljava/lang/String;")), is(true)); | ||
| 159 | assertThat(m_index.containsObfField(newField("none/a", "b", "Ljava/lang/String;")), is(false)); | ||
| 160 | assertThat(m_index.containsObfField(newField("none/a", "a", "LFoo;")), is(false)); | ||
| 161 | assertThat(m_index.containsObfBehavior(newMethod("none/a", "a", "()Ljava/lang/String;")), is(true)); | ||
| 162 | assertThat(m_index.containsObfBehavior(newMethod("none/a", "b", "()Ljava/lang/String;")), is(false)); | ||
| 163 | } | ||
| 164 | } | ||
diff --git a/src/test/java/cuchaz/enigma/TestSignature.java b/src/test/java/cuchaz/enigma/TestSignature.java new file mode 100644 index 00000000..8537adfb --- /dev/null +++ b/src/test/java/cuchaz/enigma/TestSignature.java | |||
| @@ -0,0 +1,268 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma; | ||
| 12 | |||
| 13 | import static org.hamcrest.MatcherAssert.*; | ||
| 14 | import static org.hamcrest.Matchers.*; | ||
| 15 | |||
| 16 | import org.junit.Test; | ||
| 17 | |||
| 18 | import cuchaz.enigma.mapping.ClassNameReplacer; | ||
| 19 | import cuchaz.enigma.mapping.Signature; | ||
| 20 | import cuchaz.enigma.mapping.Type; | ||
| 21 | |||
| 22 | |||
| 23 | public class TestSignature { | ||
| 24 | |||
| 25 | @Test | ||
| 26 | public void easiest() { | ||
| 27 | final Signature sig = new Signature("()V"); | ||
| 28 | assertThat(sig.getArgumentTypes(), is(empty())); | ||
| 29 | assertThat(sig.getReturnType(), is(new Type("V"))); | ||
| 30 | } | ||
| 31 | |||
| 32 | @Test | ||
| 33 | public void primitives() { | ||
| 34 | { | ||
| 35 | final Signature sig = new Signature("(I)V"); | ||
| 36 | assertThat(sig.getArgumentTypes(), contains( | ||
| 37 | new Type("I") | ||
| 38 | )); | ||
| 39 | assertThat(sig.getReturnType(), is(new Type("V"))); | ||
| 40 | } | ||
| 41 | { | ||
| 42 | final Signature sig = new Signature("(I)I"); | ||
| 43 | assertThat(sig.getArgumentTypes(), contains( | ||
| 44 | new Type("I") | ||
| 45 | )); | ||
| 46 | assertThat(sig.getReturnType(), is(new Type("I"))); | ||
| 47 | } | ||
| 48 | { | ||
| 49 | final Signature sig = new Signature("(IBCJ)Z"); | ||
| 50 | assertThat(sig.getArgumentTypes(), contains( | ||
| 51 | new Type("I"), | ||
| 52 | new Type("B"), | ||
| 53 | new Type("C"), | ||
| 54 | new Type("J") | ||
| 55 | )); | ||
| 56 | assertThat(sig.getReturnType(), is(new Type("Z"))); | ||
| 57 | } | ||
| 58 | } | ||
| 59 | |||
| 60 | @Test | ||
| 61 | public void classes() { | ||
| 62 | { | ||
| 63 | final Signature sig = new Signature("([LFoo;)V"); | ||
| 64 | assertThat(sig.getArgumentTypes().size(), is(1)); | ||
| 65 | assertThat(sig.getArgumentTypes().get(0), is(new Type("[LFoo;"))); | ||
| 66 | assertThat(sig.getReturnType(), is(new Type("V"))); | ||
| 67 | } | ||
| 68 | { | ||
| 69 | final Signature sig = new Signature("(LFoo;)LBar;"); | ||
| 70 | assertThat(sig.getArgumentTypes(), contains( | ||
| 71 | new Type("LFoo;") | ||
| 72 | )); | ||
| 73 | assertThat(sig.getReturnType(), is(new Type("LBar;"))); | ||
| 74 | } | ||
| 75 | { | ||
| 76 | final Signature sig = new Signature("(LFoo;LMoo;LZoo;)LBar;"); | ||
| 77 | assertThat(sig.getArgumentTypes(), contains( | ||
| 78 | new Type("LFoo;"), | ||
| 79 | new Type("LMoo;"), | ||
| 80 | new Type("LZoo;") | ||
| 81 | )); | ||
| 82 | assertThat(sig.getReturnType(), is(new Type("LBar;"))); | ||
| 83 | } | ||
| 84 | } | ||
| 85 | |||
| 86 | @Test | ||
| 87 | public void arrays() { | ||
| 88 | { | ||
| 89 | final Signature sig = new Signature("([I)V"); | ||
| 90 | assertThat(sig.getArgumentTypes(), contains( | ||
| 91 | new Type("[I") | ||
| 92 | )); | ||
| 93 | assertThat(sig.getReturnType(), is(new Type("V"))); | ||
| 94 | } | ||
| 95 | { | ||
| 96 | final Signature sig = new Signature("([I)[J"); | ||
| 97 | assertThat(sig.getArgumentTypes(), contains( | ||
| 98 | new Type("[I") | ||
| 99 | )); | ||
| 100 | assertThat(sig.getReturnType(), is(new Type("[J"))); | ||
| 101 | } | ||
| 102 | { | ||
| 103 | final Signature sig = new Signature("([I[Z[F)[D"); | ||
| 104 | assertThat(sig.getArgumentTypes(), contains( | ||
| 105 | new Type("[I"), | ||
| 106 | new Type("[Z"), | ||
| 107 | new Type("[F") | ||
| 108 | )); | ||
| 109 | assertThat(sig.getReturnType(), is(new Type("[D"))); | ||
| 110 | } | ||
| 111 | } | ||
| 112 | |||
| 113 | @Test | ||
| 114 | public void mixed() { | ||
| 115 | { | ||
| 116 | final Signature sig = new Signature("(I[JLFoo;)Z"); | ||
| 117 | assertThat(sig.getArgumentTypes(), contains( | ||
| 118 | new Type("I"), | ||
| 119 | new Type("[J"), | ||
| 120 | new Type("LFoo;") | ||
| 121 | )); | ||
| 122 | assertThat(sig.getReturnType(), is(new Type("Z"))); | ||
| 123 | } | ||
| 124 | { | ||
| 125 | final Signature sig = new Signature("(III)[LFoo;"); | ||
| 126 | assertThat(sig.getArgumentTypes(), contains( | ||
| 127 | new Type("I"), | ||
| 128 | new Type("I"), | ||
| 129 | new Type("I") | ||
| 130 | )); | ||
| 131 | assertThat(sig.getReturnType(), is(new Type("[LFoo;"))); | ||
| 132 | } | ||
| 133 | } | ||
| 134 | |||
| 135 | @Test | ||
| 136 | public void replaceClasses() { | ||
| 137 | { | ||
| 138 | final Signature oldSig = new Signature("()V"); | ||
| 139 | final Signature sig = new Signature(oldSig, new ClassNameReplacer() { | ||
| 140 | @Override | ||
| 141 | public String replace(String val) { | ||
| 142 | return null; | ||
| 143 | } | ||
| 144 | }); | ||
| 145 | assertThat(sig.getArgumentTypes(), is(empty())); | ||
| 146 | assertThat(sig.getReturnType(), is(new Type("V"))); | ||
| 147 | } | ||
| 148 | { | ||
| 149 | final Signature oldSig = new Signature("(IJLFoo;)V"); | ||
| 150 | final Signature sig = new Signature(oldSig, new ClassNameReplacer() { | ||
| 151 | @Override | ||
| 152 | public String replace(String val) { | ||
| 153 | return null; | ||
| 154 | } | ||
| 155 | }); | ||
| 156 | assertThat(sig.getArgumentTypes(), contains( | ||
| 157 | new Type("I"), | ||
| 158 | new Type("J"), | ||
| 159 | new Type("LFoo;") | ||
| 160 | )); | ||
| 161 | assertThat(sig.getReturnType(), is(new Type("V"))); | ||
| 162 | } | ||
| 163 | { | ||
| 164 | final Signature oldSig = new Signature("(LFoo;LBar;)LMoo;"); | ||
| 165 | final Signature sig = new Signature(oldSig, new ClassNameReplacer() { | ||
| 166 | @Override | ||
| 167 | public String replace(String val) { | ||
| 168 | if (val.equals("Foo")) { | ||
| 169 | return "Bar"; | ||
| 170 | } | ||
| 171 | return null; | ||
| 172 | } | ||
| 173 | }); | ||
| 174 | assertThat(sig.getArgumentTypes(), contains( | ||
| 175 | new Type("LBar;"), | ||
| 176 | new Type("LBar;") | ||
| 177 | )); | ||
| 178 | assertThat(sig.getReturnType(), is(new Type("LMoo;"))); | ||
| 179 | } | ||
| 180 | { | ||
| 181 | final Signature oldSig = new Signature("(LFoo;LBar;)LMoo;"); | ||
| 182 | final Signature sig = new Signature(oldSig, new ClassNameReplacer() { | ||
| 183 | @Override | ||
| 184 | public String replace(String val) { | ||
| 185 | if (val.equals("Moo")) { | ||
| 186 | return "Cow"; | ||
| 187 | } | ||
| 188 | return null; | ||
| 189 | } | ||
| 190 | }); | ||
| 191 | assertThat(sig.getArgumentTypes(), contains( | ||
| 192 | new Type("LFoo;"), | ||
| 193 | new Type("LBar;") | ||
| 194 | )); | ||
| 195 | assertThat(sig.getReturnType(), is(new Type("LCow;"))); | ||
| 196 | } | ||
| 197 | } | ||
| 198 | |||
| 199 | @Test | ||
| 200 | public void replaceArrayClasses() { | ||
| 201 | { | ||
| 202 | final Signature oldSig = new Signature("([LFoo;)[[[LBar;"); | ||
| 203 | final Signature sig = new Signature(oldSig, new ClassNameReplacer() { | ||
| 204 | @Override | ||
| 205 | public String replace(String val) { | ||
| 206 | if (val.equals("Foo")) { | ||
| 207 | return "Food"; | ||
| 208 | } else if (val.equals("Bar")) { | ||
| 209 | return "Beer"; | ||
| 210 | } | ||
| 211 | return null; | ||
| 212 | } | ||
| 213 | }); | ||
| 214 | assertThat(sig.getArgumentTypes(), contains( | ||
| 215 | new Type("[LFood;") | ||
| 216 | )); | ||
| 217 | assertThat(sig.getReturnType(), is(new Type("[[[LBeer;"))); | ||
| 218 | } | ||
| 219 | } | ||
| 220 | |||
| 221 | @Test | ||
| 222 | public void equals() { | ||
| 223 | |||
| 224 | // base | ||
| 225 | assertThat(new Signature("()V"), is(new Signature("()V"))); | ||
| 226 | |||
| 227 | // arguments | ||
| 228 | assertThat(new Signature("(I)V"), is(new Signature("(I)V"))); | ||
| 229 | assertThat(new Signature("(ZIZ)V"), is(new Signature("(ZIZ)V"))); | ||
| 230 | assertThat(new Signature("(LFoo;)V"), is(new Signature("(LFoo;)V"))); | ||
| 231 | assertThat(new Signature("(LFoo;LBar;)V"), is(new Signature("(LFoo;LBar;)V"))); | ||
| 232 | assertThat(new Signature("([I)V"), is(new Signature("([I)V"))); | ||
| 233 | assertThat(new Signature("([[D[[[J)V"), is(new Signature("([[D[[[J)V"))); | ||
| 234 | |||
| 235 | assertThat(new Signature("()V"), is(not(new Signature("(I)V")))); | ||
| 236 | assertThat(new Signature("(I)V"), is(not(new Signature("()V")))); | ||
| 237 | assertThat(new Signature("(IJ)V"), is(not(new Signature("(JI)V")))); | ||
| 238 | assertThat(new Signature("([[Z)V"), is(not(new Signature("([[LFoo;)V")))); | ||
| 239 | assertThat(new Signature("(LFoo;LBar;)V"), is(not(new Signature("(LFoo;LCow;)V")))); | ||
| 240 | assertThat(new Signature("([LFoo;LBar;)V"), is(not(new Signature("(LFoo;LCow;)V")))); | ||
| 241 | |||
| 242 | // return type | ||
| 243 | assertThat(new Signature("()I"), is(new Signature("()I"))); | ||
| 244 | assertThat(new Signature("()Z"), is(new Signature("()Z"))); | ||
| 245 | assertThat(new Signature("()[D"), is(new Signature("()[D"))); | ||
| 246 | assertThat(new Signature("()[[[Z"), is(new Signature("()[[[Z"))); | ||
| 247 | assertThat(new Signature("()LFoo;"), is(new Signature("()LFoo;"))); | ||
| 248 | assertThat(new Signature("()[LFoo;"), is(new Signature("()[LFoo;"))); | ||
| 249 | |||
| 250 | assertThat(new Signature("()I"), is(not(new Signature("()Z")))); | ||
| 251 | assertThat(new Signature("()Z"), is(not(new Signature("()I")))); | ||
| 252 | assertThat(new Signature("()[D"), is(not(new Signature("()[J")))); | ||
| 253 | assertThat(new Signature("()[[[Z"), is(not(new Signature("()[[Z")))); | ||
| 254 | assertThat(new Signature("()LFoo;"), is(not(new Signature("()LBar;")))); | ||
| 255 | assertThat(new Signature("()[LFoo;"), is(not(new Signature("()[LBar;")))); | ||
| 256 | } | ||
| 257 | |||
| 258 | @Test | ||
| 259 | public void testToString() { | ||
| 260 | assertThat(new Signature("()V").toString(), is("()V")); | ||
| 261 | assertThat(new Signature("(I)V").toString(), is("(I)V")); | ||
| 262 | assertThat(new Signature("(ZIZ)V").toString(), is("(ZIZ)V")); | ||
| 263 | assertThat(new Signature("(LFoo;)V").toString(), is("(LFoo;)V")); | ||
| 264 | assertThat(new Signature("(LFoo;LBar;)V").toString(), is("(LFoo;LBar;)V")); | ||
| 265 | assertThat(new Signature("([I)V").toString(), is("([I)V")); | ||
| 266 | assertThat(new Signature("([[D[[[J)V").toString(), is("([[D[[[J)V")); | ||
| 267 | } | ||
| 268 | } | ||
diff --git a/src/test/java/cuchaz/enigma/TestSourceIndex.java b/src/test/java/cuchaz/enigma/TestSourceIndex.java new file mode 100644 index 00000000..58d9ca91 --- /dev/null +++ b/src/test/java/cuchaz/enigma/TestSourceIndex.java | |||
| @@ -0,0 +1,67 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma; | ||
| 12 | |||
| 13 | import java.io.File; | ||
| 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 | @Test | ||
| 26 | public void indexEverything() | ||
| 27 | throws Exception { | ||
| 28 | // Figure out where Minecraft is... | ||
| 29 | final String mcDir = System.getProperty("enigma.test.minecraftdir"); | ||
| 30 | File mcJar = null; | ||
| 31 | if (mcDir == null) { | ||
| 32 | String osname = System.getProperty("os.name").toLowerCase(); | ||
| 33 | if (osname.contains("nix") || osname.contains("nux") || osname.contains("solaris")) { | ||
| 34 | mcJar = new File(System.getProperty("user.home"), ".minecraft/versions/1.8.3/1.8.3.jar"); | ||
| 35 | } | ||
| 36 | else if (osname.contains("mac") || osname.contains("darwin")) { | ||
| 37 | mcJar = new File(System.getProperty("user.home"), "Library/Application Support/minecraft/versions/1.8.3/1.8.3.jar"); | ||
| 38 | } | ||
| 39 | else if (osname.contains("win")) { | ||
| 40 | mcJar = new File(System.getenv("AppData"), ".minecraft/versions/1.8.3/1.8.3.jar"); | ||
| 41 | } | ||
| 42 | } | ||
| 43 | else { | ||
| 44 | mcJar = new File(mcDir, "versions/1.8.3/1.8.3.jar"); | ||
| 45 | } | ||
| 46 | |||
| 47 | Deobfuscator deobfuscator = new Deobfuscator(new JarFile(mcJar)); | ||
| 48 | |||
| 49 | // get all classes that aren't inner classes | ||
| 50 | Set<ClassEntry> classEntries = Sets.newHashSet(); | ||
| 51 | for (ClassEntry obfClassEntry : deobfuscator.getJarIndex().getObfClassEntries()) { | ||
| 52 | if (!obfClassEntry.isInnerClass()) { | ||
| 53 | classEntries.add(obfClassEntry); | ||
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 57 | for (ClassEntry obfClassEntry : classEntries) { | ||
| 58 | try { | ||
| 59 | CompilationUnit tree = deobfuscator.getSourceTree(obfClassEntry.getName()); | ||
| 60 | String source = deobfuscator.getSource(tree); | ||
| 61 | deobfuscator.getSourceIndex(tree, source); | ||
| 62 | } catch (Throwable t) { | ||
| 63 | throw new Error("Unable to index " + obfClassEntry, t); | ||
| 64 | } | ||
| 65 | } | ||
| 66 | } | ||
| 67 | } | ||
diff --git a/src/test/java/cuchaz/enigma/TestTokensConstructors.java b/src/test/java/cuchaz/enigma/TestTokensConstructors.java new file mode 100644 index 00000000..66c6fd1b --- /dev/null +++ b/src/test/java/cuchaz/enigma/TestTokensConstructors.java | |||
| @@ -0,0 +1,136 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma; | ||
| 12 | |||
| 13 | import static cuchaz.enigma.TestEntryFactory.*; | ||
| 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/test-obf/constructors.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/src/test/java/cuchaz/enigma/TestTranslator.java b/src/test/java/cuchaz/enigma/TestTranslator.java new file mode 100644 index 00000000..7a430d38 --- /dev/null +++ b/src/test/java/cuchaz/enigma/TestTranslator.java | |||
| @@ -0,0 +1,171 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma; | ||
| 12 | |||
| 13 | import static cuchaz.enigma.TestEntryFactory.*; | ||
| 14 | import static org.hamcrest.MatcherAssert.*; | ||
| 15 | import static org.hamcrest.Matchers.*; | ||
| 16 | |||
| 17 | import java.io.InputStream; | ||
| 18 | import java.io.InputStreamReader; | ||
| 19 | import java.util.jar.JarFile; | ||
| 20 | |||
| 21 | import org.junit.BeforeClass; | ||
| 22 | import org.junit.Test; | ||
| 23 | |||
| 24 | import cuchaz.enigma.mapping.Entry; | ||
| 25 | import cuchaz.enigma.mapping.Mappings; | ||
| 26 | import cuchaz.enigma.mapping.MappingsReader; | ||
| 27 | import cuchaz.enigma.mapping.TranslationDirection; | ||
| 28 | import cuchaz.enigma.mapping.Translator; | ||
| 29 | |||
| 30 | |||
| 31 | public class TestTranslator { | ||
| 32 | |||
| 33 | private static Deobfuscator m_deobfuscator; | ||
| 34 | private static Mappings m_mappings; | ||
| 35 | private static Translator m_deobfTranslator; | ||
| 36 | private static Translator m_obfTranslator; | ||
| 37 | |||
| 38 | @BeforeClass | ||
| 39 | public static void beforeClass() | ||
| 40 | throws Exception { | ||
| 41 | //TODO FIx | ||
| 42 | // m_deobfuscator = new Deobfuscator(new JarFile("build/test-obf/translation.jar")); | ||
| 43 | // try (InputStream in = TestTranslator.class.getResourceAsStream("/cuchaz/enigma/resources/translation.mappings")) { | ||
| 44 | // m_mappings = new MappingsReader().read(new InputStreamReader(in)); | ||
| 45 | // m_deobfuscator.setMappings(m_mappings); | ||
| 46 | // m_deobfTranslator = m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating); | ||
| 47 | // m_obfTranslator = m_deobfuscator.getTranslator(TranslationDirection.Obfuscating); | ||
| 48 | // } | ||
| 49 | } | ||
| 50 | |||
| 51 | @Test | ||
| 52 | public void basicClasses() { | ||
| 53 | assertMapping(newClass("none/a"), newClass("deobf/A_Basic")); | ||
| 54 | assertMapping(newClass("none/b"), newClass("deobf/B_BaseClass")); | ||
| 55 | assertMapping(newClass("none/c"), newClass("deobf/C_SubClass")); | ||
| 56 | } | ||
| 57 | |||
| 58 | @Test | ||
| 59 | public void basicFields() { | ||
| 60 | assertMapping(newField("none/a", "a", "I"), newField("deobf/A_Basic", "f1", "I")); | ||
| 61 | assertMapping(newField("none/a", "a", "F"), newField("deobf/A_Basic", "f2", "F")); | ||
| 62 | assertMapping(newField("none/a", "a", "Ljava/lang/String;"), newField("deobf/A_Basic", "f3", "Ljava/lang/String;")); | ||
| 63 | } | ||
| 64 | |||
| 65 | @Test | ||
| 66 | public void basicMethods() { | ||
| 67 | assertMapping(newMethod("none/a", "a", "()V"), newMethod("deobf/A_Basic", "m1", "()V")); | ||
| 68 | assertMapping(newMethod("none/a", "a", "()I"), newMethod("deobf/A_Basic", "m2", "()I")); | ||
| 69 | assertMapping(newMethod("none/a", "a", "(I)V"), newMethod("deobf/A_Basic", "m3", "(I)V")); | ||
| 70 | assertMapping(newMethod("none/a", "a", "(I)I"), newMethod("deobf/A_Basic", "m4", "(I)I")); | ||
| 71 | } | ||
| 72 | |||
| 73 | // TODO: basic constructors | ||
| 74 | |||
| 75 | @Test | ||
| 76 | public void inheritanceFields() { | ||
| 77 | assertMapping(newField("none/b", "a", "I"), newField("deobf/B_BaseClass", "f1", "I")); | ||
| 78 | assertMapping(newField("none/b", "a", "C"), newField("deobf/B_BaseClass", "f2", "C")); | ||
| 79 | assertMapping(newField("none/c", "b", "I"), newField("deobf/C_SubClass", "f3", "I")); | ||
| 80 | assertMapping(newField("none/c", "c", "I"), newField("deobf/C_SubClass", "f4", "I")); | ||
| 81 | } | ||
| 82 | |||
| 83 | @Test | ||
| 84 | public void inheritanceFieldsShadowing() { | ||
| 85 | assertMapping(newField("none/c", "b", "C"), newField("deobf/C_SubClass", "f2", "C")); | ||
| 86 | } | ||
| 87 | |||
| 88 | @Test | ||
| 89 | public void inheritanceFieldsBySubClass() { | ||
| 90 | assertMapping(newField("none/c", "a", "I"), newField("deobf/C_SubClass", "f1", "I")); | ||
| 91 | // NOTE: can't reference b.C by subclass since it's shadowed | ||
| 92 | } | ||
| 93 | |||
| 94 | @Test | ||
| 95 | public void inheritanceMethods() { | ||
| 96 | assertMapping(newMethod("none/b", "a", "()I"), newMethod("deobf/B_BaseClass", "m1", "()I")); | ||
| 97 | assertMapping(newMethod("none/b", "b", "()I"), newMethod("deobf/B_BaseClass", "m2", "()I")); | ||
| 98 | assertMapping(newMethod("none/c", "c", "()I"), newMethod("deobf/C_SubClass", "m3", "()I")); | ||
| 99 | } | ||
| 100 | |||
| 101 | @Test | ||
| 102 | public void inheritanceMethodsOverrides() { | ||
| 103 | assertMapping(newMethod("none/c", "a", "()I"), newMethod("deobf/C_SubClass", "m1", "()I")); | ||
| 104 | } | ||
| 105 | |||
| 106 | @Test | ||
| 107 | public void inheritanceMethodsBySubClass() { | ||
| 108 | assertMapping(newMethod("none/c", "b", "()I"), newMethod("deobf/C_SubClass", "m2", "()I")); | ||
| 109 | } | ||
| 110 | |||
| 111 | @Test | ||
| 112 | public void innerClasses() { | ||
| 113 | |||
| 114 | // classes | ||
| 115 | assertMapping(newClass("none/g"), newClass("deobf/G_OuterClass")); | ||
| 116 | assertMapping(newClass("none/g$a"), newClass("deobf/G_OuterClass$A_InnerClass")); | ||
| 117 | assertMapping(newClass("none/g$a$a"), newClass("deobf/G_OuterClass$A_InnerClass$A_InnerInnerClass")); | ||
| 118 | assertMapping(newClass("none/g$b"), newClass("deobf/G_OuterClass$b")); | ||
| 119 | assertMapping(newClass("none/g$b$a"), newClass("deobf/G_OuterClass$b$A_NamedInnerClass")); | ||
| 120 | |||
| 121 | // fields | ||
| 122 | assertMapping(newField("none/g$a", "a", "I"), newField("deobf/G_OuterClass$A_InnerClass", "f1", "I")); | ||
| 123 | assertMapping(newField("none/g$a", "a", "Ljava/lang/String;"), newField("deobf/G_OuterClass$A_InnerClass", "f2", "Ljava/lang/String;")); | ||
| 124 | assertMapping(newField("none/g$a$a", "a", "I"), newField("deobf/G_OuterClass$A_InnerClass$A_InnerInnerClass", "f3", "I")); | ||
| 125 | assertMapping(newField("none/g$b$a", "a", "I"), newField("deobf/G_OuterClass$b$A_NamedInnerClass", "f4", "I")); | ||
| 126 | |||
| 127 | // methods | ||
| 128 | assertMapping(newMethod("none/g$a", "a", "()V"), newMethod("deobf/G_OuterClass$A_InnerClass", "m1", "()V")); | ||
| 129 | assertMapping(newMethod("none/g$a$a", "a", "()V"), newMethod("deobf/G_OuterClass$A_InnerClass$A_InnerInnerClass", "m2", "()V")); | ||
| 130 | } | ||
| 131 | |||
| 132 | @Test | ||
| 133 | public void namelessClass() { | ||
| 134 | assertMapping(newClass("none/h"), newClass("none/h")); | ||
| 135 | } | ||
| 136 | |||
| 137 | @Test | ||
| 138 | public void testGenerics() { | ||
| 139 | |||
| 140 | // classes | ||
| 141 | assertMapping(newClass("none/i"), newClass("deobf/I_Generics")); | ||
| 142 | assertMapping(newClass("none/i$a"), newClass("deobf/I_Generics$A_Type")); | ||
| 143 | assertMapping(newClass("none/i$b"), newClass("deobf/I_Generics$B_Generic")); | ||
| 144 | |||
| 145 | // fields | ||
| 146 | assertMapping(newField("none/i", "a", "Ljava/util/List;"), newField("deobf/I_Generics", "f1", "Ljava/util/List;")); | ||
| 147 | assertMapping(newField("none/i", "b", "Ljava/util/List;"), newField("deobf/I_Generics", "f2", "Ljava/util/List;")); | ||
| 148 | assertMapping(newField("none/i", "a", "Ljava/util/Map;"), newField("deobf/I_Generics", "f3", "Ljava/util/Map;")); | ||
| 149 | assertMapping(newField("none/i$b", "a", "Ljava/lang/Object;"), newField("deobf/I_Generics$B_Generic", "f4", "Ljava/lang/Object;")); | ||
| 150 | assertMapping(newField("none/i", "a", "Lnone/i$b;"), newField("deobf/I_Generics", "f5", "Ldeobf/I_Generics$B_Generic;")); | ||
| 151 | assertMapping(newField("none/i", "b", "Lnone/i$b;"), newField("deobf/I_Generics", "f6", "Ldeobf/I_Generics$B_Generic;")); | ||
| 152 | |||
| 153 | // methods | ||
| 154 | assertMapping(newMethod("none/i$b", "a", "()Ljava/lang/Object;"), newMethod("deobf/I_Generics$B_Generic", "m1", "()Ljava/lang/Object;")); | ||
| 155 | } | ||
| 156 | |||
| 157 | private void assertMapping(Entry obf, Entry deobf) { | ||
| 158 | assertThat(m_deobfTranslator.translateEntry(obf), is(deobf)); | ||
| 159 | assertThat(m_obfTranslator.translateEntry(deobf), is(obf)); | ||
| 160 | |||
| 161 | String deobfName = m_deobfTranslator.translate(obf); | ||
| 162 | if (deobfName != null) { | ||
| 163 | assertThat(deobfName, is(deobf.getName())); | ||
| 164 | } | ||
| 165 | |||
| 166 | String obfName = m_obfTranslator.translate(deobf); | ||
| 167 | if (obfName != null) { | ||
| 168 | assertThat(obfName, is(obf.getName())); | ||
| 169 | } | ||
| 170 | } | ||
| 171 | } | ||
diff --git a/src/test/java/cuchaz/enigma/TestType.java b/src/test/java/cuchaz/enigma/TestType.java new file mode 100644 index 00000000..01c235b8 --- /dev/null +++ b/src/test/java/cuchaz/enigma/TestType.java | |||
| @@ -0,0 +1,243 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma; | ||
| 12 | |||
| 13 | import static cuchaz.enigma.TestEntryFactory.*; | ||
| 14 | import static org.hamcrest.MatcherAssert.*; | ||
| 15 | import static org.hamcrest.Matchers.*; | ||
| 16 | |||
| 17 | import org.junit.Test; | ||
| 18 | |||
| 19 | import cuchaz.enigma.mapping.Type; | ||
| 20 | |||
| 21 | |||
| 22 | public class TestType { | ||
| 23 | |||
| 24 | @Test | ||
| 25 | public void isVoid() { | ||
| 26 | assertThat(new Type("V").isVoid(), is(true)); | ||
| 27 | assertThat(new Type("Z").isVoid(), is(false)); | ||
| 28 | assertThat(new Type("B").isVoid(), is(false)); | ||
| 29 | assertThat(new Type("C").isVoid(), is(false)); | ||
| 30 | assertThat(new Type("I").isVoid(), is(false)); | ||
| 31 | assertThat(new Type("J").isVoid(), is(false)); | ||
| 32 | assertThat(new Type("F").isVoid(), is(false)); | ||
| 33 | assertThat(new Type("D").isVoid(), is(false)); | ||
| 34 | assertThat(new Type("LFoo;").isVoid(), is(false)); | ||
| 35 | assertThat(new Type("[I").isVoid(), is(false)); | ||
| 36 | } | ||
| 37 | |||
| 38 | @Test | ||
| 39 | public void isPrimitive() { | ||
| 40 | assertThat(new Type("V").isPrimitive(), is(false)); | ||
| 41 | assertThat(new Type("Z").isPrimitive(), is(true)); | ||
| 42 | assertThat(new Type("B").isPrimitive(), is(true)); | ||
| 43 | assertThat(new Type("C").isPrimitive(), is(true)); | ||
| 44 | assertThat(new Type("I").isPrimitive(), is(true)); | ||
| 45 | assertThat(new Type("J").isPrimitive(), is(true)); | ||
| 46 | assertThat(new Type("F").isPrimitive(), is(true)); | ||
| 47 | assertThat(new Type("D").isPrimitive(), is(true)); | ||
| 48 | assertThat(new Type("LFoo;").isPrimitive(), is(false)); | ||
| 49 | assertThat(new Type("[I").isPrimitive(), is(false)); | ||
| 50 | } | ||
| 51 | |||
| 52 | @Test | ||
| 53 | public void getPrimitive() { | ||
| 54 | assertThat(new Type("Z").getPrimitive(), is(Type.Primitive.Boolean)); | ||
| 55 | assertThat(new Type("B").getPrimitive(), is(Type.Primitive.Byte)); | ||
| 56 | assertThat(new Type("C").getPrimitive(), is(Type.Primitive.Character)); | ||
| 57 | assertThat(new Type("I").getPrimitive(), is(Type.Primitive.Integer)); | ||
| 58 | assertThat(new Type("J").getPrimitive(), is(Type.Primitive.Long)); | ||
| 59 | assertThat(new Type("F").getPrimitive(), is(Type.Primitive.Float)); | ||
| 60 | assertThat(new Type("D").getPrimitive(), is(Type.Primitive.Double)); | ||
| 61 | } | ||
| 62 | |||
| 63 | @Test | ||
| 64 | public void isClass() { | ||
| 65 | assertThat(new Type("V").isClass(), is(false)); | ||
| 66 | assertThat(new Type("Z").isClass(), is(false)); | ||
| 67 | assertThat(new Type("B").isClass(), is(false)); | ||
| 68 | assertThat(new Type("C").isClass(), is(false)); | ||
| 69 | assertThat(new Type("I").isClass(), is(false)); | ||
| 70 | assertThat(new Type("J").isClass(), is(false)); | ||
| 71 | assertThat(new Type("F").isClass(), is(false)); | ||
| 72 | assertThat(new Type("D").isClass(), is(false)); | ||
| 73 | assertThat(new Type("LFoo;").isClass(), is(true)); | ||
| 74 | assertThat(new Type("[I").isClass(), is(false)); | ||
| 75 | } | ||
| 76 | |||
| 77 | @Test | ||
| 78 | public void getClassEntry() { | ||
| 79 | assertThat(new Type("LFoo;").getClassEntry(), is(newClass("Foo"))); | ||
| 80 | assertThat(new Type("Ljava/lang/String;").getClassEntry(), is(newClass("java/lang/String"))); | ||
| 81 | } | ||
| 82 | |||
| 83 | @Test | ||
| 84 | public void getArrayClassEntry() { | ||
| 85 | assertThat(new Type("[LFoo;").getClassEntry(), is(newClass("Foo"))); | ||
| 86 | assertThat(new Type("[[[Ljava/lang/String;").getClassEntry(), is(newClass("java/lang/String"))); | ||
| 87 | } | ||
| 88 | |||
| 89 | @Test | ||
| 90 | public void isArray() { | ||
| 91 | assertThat(new Type("V").isArray(), is(false)); | ||
| 92 | assertThat(new Type("Z").isArray(), is(false)); | ||
| 93 | assertThat(new Type("B").isArray(), is(false)); | ||
| 94 | assertThat(new Type("C").isArray(), is(false)); | ||
| 95 | assertThat(new Type("I").isArray(), is(false)); | ||
| 96 | assertThat(new Type("J").isArray(), is(false)); | ||
| 97 | assertThat(new Type("F").isArray(), is(false)); | ||
| 98 | assertThat(new Type("D").isArray(), is(false)); | ||
| 99 | assertThat(new Type("LFoo;").isArray(), is(false)); | ||
| 100 | assertThat(new Type("[I").isArray(), is(true)); | ||
| 101 | } | ||
| 102 | |||
| 103 | @Test | ||
| 104 | public void getArrayDimension() { | ||
| 105 | assertThat(new Type("[I").getArrayDimension(), is(1)); | ||
| 106 | assertThat(new Type("[[I").getArrayDimension(), is(2)); | ||
| 107 | assertThat(new Type("[[[I").getArrayDimension(), is(3)); | ||
| 108 | } | ||
| 109 | |||
| 110 | @Test | ||
| 111 | public void getArrayType() { | ||
| 112 | assertThat(new Type("[I").getArrayType(), is(new Type("I"))); | ||
| 113 | assertThat(new Type("[[I").getArrayType(), is(new Type("I"))); | ||
| 114 | assertThat(new Type("[[[I").getArrayType(), is(new Type("I"))); | ||
| 115 | assertThat(new Type("[Ljava/lang/String;").getArrayType(), is(new Type("Ljava/lang/String;"))); | ||
| 116 | } | ||
| 117 | |||
| 118 | @Test | ||
| 119 | public void hasClass() { | ||
| 120 | assertThat(new Type("LFoo;").hasClass(), is(true)); | ||
| 121 | assertThat(new Type("Ljava/lang/String;").hasClass(), is(true)); | ||
| 122 | assertThat(new Type("[LBar;").hasClass(), is(true)); | ||
| 123 | assertThat(new Type("[[[LCat;").hasClass(), is(true)); | ||
| 124 | |||
| 125 | assertThat(new Type("V").hasClass(), is(false)); | ||
| 126 | assertThat(new Type("[I").hasClass(), is(false)); | ||
| 127 | assertThat(new Type("[[[I").hasClass(), is(false)); | ||
| 128 | assertThat(new Type("Z").hasClass(), is(false)); | ||
| 129 | } | ||
| 130 | |||
| 131 | @Test | ||
| 132 | public void parseVoid() { | ||
| 133 | final String answer = "V"; | ||
| 134 | assertThat(Type.parseFirst("V"), is(answer)); | ||
| 135 | assertThat(Type.parseFirst("VVV"), is(answer)); | ||
| 136 | assertThat(Type.parseFirst("VIJ"), is(answer)); | ||
| 137 | assertThat(Type.parseFirst("V[I"), is(answer)); | ||
| 138 | assertThat(Type.parseFirst("VLFoo;"), is(answer)); | ||
| 139 | assertThat(Type.parseFirst("V[LFoo;"), is(answer)); | ||
| 140 | } | ||
| 141 | |||
| 142 | @Test | ||
| 143 | public void parsePrimitive() { | ||
| 144 | final String answer = "I"; | ||
| 145 | assertThat(Type.parseFirst("I"), is(answer)); | ||
| 146 | assertThat(Type.parseFirst("III"), is(answer)); | ||
| 147 | assertThat(Type.parseFirst("IJZ"), is(answer)); | ||
| 148 | assertThat(Type.parseFirst("I[I"), is(answer)); | ||
| 149 | assertThat(Type.parseFirst("ILFoo;"), is(answer)); | ||
| 150 | assertThat(Type.parseFirst("I[LFoo;"), is(answer)); | ||
| 151 | } | ||
| 152 | |||
| 153 | @Test | ||
| 154 | public void parseClass() { | ||
| 155 | { | ||
| 156 | final String answer = "LFoo;"; | ||
| 157 | assertThat(Type.parseFirst("LFoo;"), is(answer)); | ||
| 158 | assertThat(Type.parseFirst("LFoo;I"), is(answer)); | ||
| 159 | assertThat(Type.parseFirst("LFoo;JZ"), is(answer)); | ||
| 160 | assertThat(Type.parseFirst("LFoo;[I"), is(answer)); | ||
| 161 | assertThat(Type.parseFirst("LFoo;LFoo;"), is(answer)); | ||
| 162 | assertThat(Type.parseFirst("LFoo;[LFoo;"), is(answer)); | ||
| 163 | } | ||
| 164 | { | ||
| 165 | final String answer = "Ljava/lang/String;"; | ||
| 166 | assertThat(Type.parseFirst("Ljava/lang/String;"), is(answer)); | ||
| 167 | assertThat(Type.parseFirst("Ljava/lang/String;I"), is(answer)); | ||
| 168 | assertThat(Type.parseFirst("Ljava/lang/String;JZ"), is(answer)); | ||
| 169 | assertThat(Type.parseFirst("Ljava/lang/String;[I"), is(answer)); | ||
| 170 | assertThat(Type.parseFirst("Ljava/lang/String;LFoo;"), is(answer)); | ||
| 171 | assertThat(Type.parseFirst("Ljava/lang/String;[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 | |||
| 218 | assertThat(new Type("V"), is(not(new Type("I")))); | ||
| 219 | assertThat(new Type("I"), is(not(new Type("J")))); | ||
| 220 | assertThat(new Type("I"), is(not(new Type("LBar;")))); | ||
| 221 | assertThat(new Type("I"), is(not(new Type("[I")))); | ||
| 222 | assertThat(new Type("LFoo;"), is(not(new Type("LBar;")))); | ||
| 223 | assertThat(new Type("[I"), is(not(new Type("[Z")))); | ||
| 224 | assertThat(new Type("[[[I"), is(not(new Type("[I")))); | ||
| 225 | assertThat(new Type("[LFoo;"), is(not(new Type("[LBar;")))); | ||
| 226 | } | ||
| 227 | |||
| 228 | @Test | ||
| 229 | public void testToString() { | ||
| 230 | assertThat(new Type("V").toString(), is("V")); | ||
| 231 | assertThat(new Type("Z").toString(), is("Z")); | ||
| 232 | assertThat(new Type("B").toString(), is("B")); | ||
| 233 | assertThat(new Type("C").toString(), is("C")); | ||
| 234 | assertThat(new Type("I").toString(), is("I")); | ||
| 235 | assertThat(new Type("J").toString(), is("J")); | ||
| 236 | assertThat(new Type("F").toString(), is("F")); | ||
| 237 | assertThat(new Type("D").toString(), is("D")); | ||
| 238 | assertThat(new Type("LFoo;").toString(), is("LFoo;")); | ||
| 239 | assertThat(new Type("[I").toString(), is("[I")); | ||
| 240 | assertThat(new Type("[[[I").toString(), is("[[[I")); | ||
| 241 | assertThat(new Type("[LFoo;").toString(), is("[LFoo;")); | ||
| 242 | } | ||
| 243 | } | ||
diff --git a/src/test/java/cuchaz/enigma/TokenChecker.java b/src/test/java/cuchaz/enigma/TokenChecker.java new file mode 100644 index 00000000..7afb4cfe --- /dev/null +++ b/src/test/java/cuchaz/enigma/TokenChecker.java | |||
| @@ -0,0 +1,65 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.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/src/test/java/cuchaz/enigma/inputs/Keep.java b/src/test/java/cuchaz/enigma/inputs/Keep.java new file mode 100644 index 00000000..f04875f5 --- /dev/null +++ b/src/test/java/cuchaz/enigma/inputs/Keep.java | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.inputs; | ||
| 12 | |||
| 13 | public class Keep { | ||
| 14 | public static void main(String[] args) { | ||
| 15 | System.out.println("Keep me!"); | ||
| 16 | } | ||
| 17 | } | ||
diff --git a/src/test/java/cuchaz/enigma/inputs/constructors/BaseClass.java b/src/test/java/cuchaz/enigma/inputs/constructors/BaseClass.java new file mode 100644 index 00000000..65e782a2 --- /dev/null +++ b/src/test/java/cuchaz/enigma/inputs/constructors/BaseClass.java | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.inputs.constructors; | ||
| 12 | |||
| 13 | // none/a | ||
| 14 | public class BaseClass { | ||
| 15 | |||
| 16 | // <init>()V | ||
| 17 | public BaseClass() { | ||
| 18 | System.out.println("Default constructor"); | ||
| 19 | } | ||
| 20 | |||
| 21 | // <init>(I)V | ||
| 22 | public BaseClass(int i) { | ||
| 23 | System.out.println("Int constructor " + i); | ||
| 24 | } | ||
| 25 | } | ||
diff --git a/src/test/java/cuchaz/enigma/inputs/constructors/Caller.java b/src/test/java/cuchaz/enigma/inputs/constructors/Caller.java new file mode 100644 index 00000000..75096ec1 --- /dev/null +++ b/src/test/java/cuchaz/enigma/inputs/constructors/Caller.java | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.inputs.constructors; | ||
| 12 | |||
| 13 | // none/b | ||
| 14 | public class Caller { | ||
| 15 | |||
| 16 | // a()V | ||
| 17 | public void callBaseDefault() { | ||
| 18 | // none/a.<init>()V | ||
| 19 | System.out.println(new BaseClass()); | ||
| 20 | } | ||
| 21 | |||
| 22 | // b()V | ||
| 23 | public void callBaseInt() { | ||
| 24 | // none/a.<init>(I)V | ||
| 25 | System.out.println(new BaseClass(5)); | ||
| 26 | } | ||
| 27 | |||
| 28 | // c()V | ||
| 29 | public void callSubDefault() { | ||
| 30 | // none/d.<init>()V | ||
| 31 | System.out.println(new SubClass()); | ||
| 32 | } | ||
| 33 | |||
| 34 | // d()V | ||
| 35 | public void callSubInt() { | ||
| 36 | // none/d.<init>(I)V | ||
| 37 | System.out.println(new SubClass(6)); | ||
| 38 | } | ||
| 39 | |||
| 40 | // e()V | ||
| 41 | public void callSubIntInt() { | ||
| 42 | // none/d.<init>(II)V | ||
| 43 | System.out.println(new SubClass(4, 2)); | ||
| 44 | } | ||
| 45 | |||
| 46 | // f()V | ||
| 47 | public void callSubSubInt() { | ||
| 48 | // none/e.<init>(I)V | ||
| 49 | System.out.println(new SubSubClass(3)); | ||
| 50 | } | ||
| 51 | |||
| 52 | // g()V | ||
| 53 | public void callDefaultConstructable() { | ||
| 54 | // none/c.<init>()V | ||
| 55 | System.out.println(new DefaultConstructable()); | ||
| 56 | } | ||
| 57 | } | ||
diff --git a/src/test/java/cuchaz/enigma/inputs/constructors/DefaultConstructable.java b/src/test/java/cuchaz/enigma/inputs/constructors/DefaultConstructable.java new file mode 100644 index 00000000..655f4da3 --- /dev/null +++ b/src/test/java/cuchaz/enigma/inputs/constructors/DefaultConstructable.java | |||
| @@ -0,0 +1,15 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.inputs.constructors; | ||
| 12 | |||
| 13 | public class DefaultConstructable { | ||
| 14 | // only default constructor | ||
| 15 | } | ||
diff --git a/src/test/java/cuchaz/enigma/inputs/constructors/SubClass.java b/src/test/java/cuchaz/enigma/inputs/constructors/SubClass.java new file mode 100644 index 00000000..b0fb3e9b --- /dev/null +++ b/src/test/java/cuchaz/enigma/inputs/constructors/SubClass.java | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.inputs.constructors; | ||
| 12 | |||
| 13 | // none/d extends none/a | ||
| 14 | public class SubClass extends BaseClass { | ||
| 15 | |||
| 16 | // <init>()V | ||
| 17 | public SubClass() { | ||
| 18 | // none/a.<init>()V | ||
| 19 | } | ||
| 20 | |||
| 21 | // <init>(I)V | ||
| 22 | public SubClass(int num) { | ||
| 23 | // <init>()V | ||
| 24 | this(); | ||
| 25 | System.out.println("SubClass " + num); | ||
| 26 | } | ||
| 27 | |||
| 28 | // <init>(II)V | ||
| 29 | public SubClass(int a, int b) { | ||
| 30 | // <init>(I)V | ||
| 31 | this(a + b); | ||
| 32 | } | ||
| 33 | |||
| 34 | // <init>(III)V | ||
| 35 | public SubClass(int a, int b, int c) { | ||
| 36 | // none/a.<init>()V | ||
| 37 | } | ||
| 38 | } | ||
diff --git a/src/test/java/cuchaz/enigma/inputs/constructors/SubSubClass.java b/src/test/java/cuchaz/enigma/inputs/constructors/SubSubClass.java new file mode 100644 index 00000000..50314050 --- /dev/null +++ b/src/test/java/cuchaz/enigma/inputs/constructors/SubSubClass.java | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.inputs.constructors; | ||
| 12 | |||
| 13 | // none/e extends none/d | ||
| 14 | public class SubSubClass extends SubClass { | ||
| 15 | |||
| 16 | // <init>(I)V | ||
| 17 | public SubSubClass(int i) { | ||
| 18 | // none/c.<init>(I)V | ||
| 19 | super(i); | ||
| 20 | } | ||
| 21 | } | ||
diff --git a/src/test/java/cuchaz/enigma/inputs/inheritanceTree/BaseClass.java b/src/test/java/cuchaz/enigma/inputs/inheritanceTree/BaseClass.java new file mode 100644 index 00000000..4f9c5b0e --- /dev/null +++ b/src/test/java/cuchaz/enigma/inputs/inheritanceTree/BaseClass.java | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.inputs.inheritanceTree; | ||
| 12 | |||
| 13 | // none/a | ||
| 14 | public abstract class BaseClass { | ||
| 15 | |||
| 16 | // a | ||
| 17 | private String m_name; | ||
| 18 | |||
| 19 | // <init>(Ljava/lang/String;)V | ||
| 20 | protected BaseClass(String name) { | ||
| 21 | m_name = name; | ||
| 22 | } | ||
| 23 | |||
| 24 | // a()Ljava/lang/String; | ||
| 25 | public String getName() { | ||
| 26 | return m_name; | ||
| 27 | } | ||
| 28 | |||
| 29 | // a()V | ||
| 30 | public abstract void doBaseThings(); | ||
| 31 | } | ||
diff --git a/src/test/java/cuchaz/enigma/inputs/inheritanceTree/SubclassA.java b/src/test/java/cuchaz/enigma/inputs/inheritanceTree/SubclassA.java new file mode 100644 index 00000000..140d2a81 --- /dev/null +++ b/src/test/java/cuchaz/enigma/inputs/inheritanceTree/SubclassA.java | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.inputs.inheritanceTree; | ||
| 12 | |||
| 13 | // none/b extends none/a | ||
| 14 | public abstract class SubclassA extends BaseClass { | ||
| 15 | |||
| 16 | // <init>(Ljava/lang/String;)V | ||
| 17 | protected SubclassA(String name) { | ||
| 18 | // call to none/a.<init>(Ljava/lang/String)V | ||
| 19 | super(name); | ||
| 20 | } | ||
| 21 | } | ||
diff --git a/src/test/java/cuchaz/enigma/inputs/inheritanceTree/SubclassB.java b/src/test/java/cuchaz/enigma/inputs/inheritanceTree/SubclassB.java new file mode 100644 index 00000000..99d149bb --- /dev/null +++ b/src/test/java/cuchaz/enigma/inputs/inheritanceTree/SubclassB.java | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.inputs.inheritanceTree; | ||
| 12 | |||
| 13 | // none/c extends none/a | ||
| 14 | public class SubclassB extends BaseClass { | ||
| 15 | |||
| 16 | // a | ||
| 17 | private int m_numThings; | ||
| 18 | |||
| 19 | // <init>()V | ||
| 20 | protected SubclassB() { | ||
| 21 | // none/a.<init>(Ljava/lang/String;)V | ||
| 22 | super("B"); | ||
| 23 | |||
| 24 | // access to a | ||
| 25 | m_numThings = 4; | ||
| 26 | } | ||
| 27 | |||
| 28 | @Override | ||
| 29 | // a()V | ||
| 30 | public void doBaseThings() { | ||
| 31 | // call to none/a.a()Ljava/lang/String; | ||
| 32 | System.out.println("Base things by B! " + getName()); | ||
| 33 | } | ||
| 34 | |||
| 35 | // b()V | ||
| 36 | public void doBThings() { | ||
| 37 | // access to a | ||
| 38 | System.out.println("" + m_numThings + " B things!"); | ||
| 39 | } | ||
| 40 | } | ||
diff --git a/src/test/java/cuchaz/enigma/inputs/inheritanceTree/SubsubclassAA.java b/src/test/java/cuchaz/enigma/inputs/inheritanceTree/SubsubclassAA.java new file mode 100644 index 00000000..2e414b75 --- /dev/null +++ b/src/test/java/cuchaz/enigma/inputs/inheritanceTree/SubsubclassAA.java | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.inputs.inheritanceTree; | ||
| 12 | |||
| 13 | // none/d extends none/b | ||
| 14 | public class SubsubclassAA extends SubclassA { | ||
| 15 | |||
| 16 | protected SubsubclassAA() { | ||
| 17 | // call to none/b.<init>(Ljava/lang/String;)V | ||
| 18 | super("AA"); | ||
| 19 | } | ||
| 20 | |||
| 21 | @Override | ||
| 22 | // a()Ljava/lang/String; | ||
| 23 | public String getName() { | ||
| 24 | // call to none/b.a()Ljava/lang/String; | ||
| 25 | return "subsub" + super.getName(); | ||
| 26 | } | ||
| 27 | |||
| 28 | @Override | ||
| 29 | // a()V | ||
| 30 | public void doBaseThings() { | ||
| 31 | // call to none/d.a()Ljava/lang/String; | ||
| 32 | System.out.println("Base things by " + getName()); | ||
| 33 | } | ||
| 34 | } | ||
diff --git a/src/test/java/cuchaz/enigma/inputs/innerClasses/A_Anonymous.java b/src/test/java/cuchaz/enigma/inputs/innerClasses/A_Anonymous.java new file mode 100644 index 00000000..f6444396 --- /dev/null +++ b/src/test/java/cuchaz/enigma/inputs/innerClasses/A_Anonymous.java | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.inputs.innerClasses; | ||
| 12 | |||
| 13 | public class A_Anonymous { | ||
| 14 | |||
| 15 | public void foo() { | ||
| 16 | Runnable runnable = new Runnable() { | ||
| 17 | @Override | ||
| 18 | public void run() { | ||
| 19 | // don't care | ||
| 20 | } | ||
| 21 | }; | ||
| 22 | runnable.run(); | ||
| 23 | } | ||
| 24 | } | ||
diff --git a/src/test/java/cuchaz/enigma/inputs/innerClasses/B_AnonymousWithScopeArgs.java b/src/test/java/cuchaz/enigma/inputs/innerClasses/B_AnonymousWithScopeArgs.java new file mode 100644 index 00000000..d78be847 --- /dev/null +++ b/src/test/java/cuchaz/enigma/inputs/innerClasses/B_AnonymousWithScopeArgs.java | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.inputs.innerClasses; | ||
| 12 | |||
| 13 | public class B_AnonymousWithScopeArgs { | ||
| 14 | |||
| 15 | public static void foo(final D_Simple arg) { | ||
| 16 | System.out.println(new Object() { | ||
| 17 | @Override | ||
| 18 | public String toString() { | ||
| 19 | return arg.toString(); | ||
| 20 | } | ||
| 21 | }); | ||
| 22 | } | ||
| 23 | } | ||
diff --git a/src/test/java/cuchaz/enigma/inputs/innerClasses/C_ConstructorArgs.java b/src/test/java/cuchaz/enigma/inputs/innerClasses/C_ConstructorArgs.java new file mode 100644 index 00000000..eb03489d --- /dev/null +++ b/src/test/java/cuchaz/enigma/inputs/innerClasses/C_ConstructorArgs.java | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.inputs.innerClasses; | ||
| 12 | |||
| 13 | @SuppressWarnings("unused") | ||
| 14 | public class C_ConstructorArgs { | ||
| 15 | |||
| 16 | class Inner { | ||
| 17 | |||
| 18 | private int a; | ||
| 19 | |||
| 20 | public Inner(int a) { | ||
| 21 | this.a = a; | ||
| 22 | } | ||
| 23 | } | ||
| 24 | |||
| 25 | Inner i; | ||
| 26 | |||
| 27 | public void foo() { | ||
| 28 | i = new Inner(5); | ||
| 29 | } | ||
| 30 | } | ||
diff --git a/src/test/java/cuchaz/enigma/inputs/innerClasses/D_Simple.java b/src/test/java/cuchaz/enigma/inputs/innerClasses/D_Simple.java new file mode 100644 index 00000000..0e9bf827 --- /dev/null +++ b/src/test/java/cuchaz/enigma/inputs/innerClasses/D_Simple.java | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.inputs.innerClasses; | ||
| 12 | |||
| 13 | public class D_Simple { | ||
| 14 | |||
| 15 | class Inner { | ||
| 16 | // nothing to do | ||
| 17 | } | ||
| 18 | } | ||
diff --git a/src/test/java/cuchaz/enigma/inputs/innerClasses/E_AnonymousWithOuterAccess.java b/src/test/java/cuchaz/enigma/inputs/innerClasses/E_AnonymousWithOuterAccess.java new file mode 100644 index 00000000..255434d1 --- /dev/null +++ b/src/test/java/cuchaz/enigma/inputs/innerClasses/E_AnonymousWithOuterAccess.java | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.inputs.innerClasses; | ||
| 12 | |||
| 13 | public class E_AnonymousWithOuterAccess { | ||
| 14 | |||
| 15 | // reproduction of error case documented at: | ||
| 16 | // https://bitbucket.org/cuchaz/enigma/issue/61/stackoverflowerror-when-deobfuscating | ||
| 17 | |||
| 18 | public Object makeInner() { | ||
| 19 | outerMethod(); | ||
| 20 | return new Object() { | ||
| 21 | @Override | ||
| 22 | public String toString() { | ||
| 23 | return outerMethod(); | ||
| 24 | } | ||
| 25 | }; | ||
| 26 | } | ||
| 27 | |||
| 28 | private String outerMethod() { | ||
| 29 | return "foo"; | ||
| 30 | } | ||
| 31 | } | ||
diff --git a/src/test/java/cuchaz/enigma/inputs/innerClasses/F_ClassTree.java b/src/test/java/cuchaz/enigma/inputs/innerClasses/F_ClassTree.java new file mode 100644 index 00000000..7d1dab41 --- /dev/null +++ b/src/test/java/cuchaz/enigma/inputs/innerClasses/F_ClassTree.java | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.inputs.innerClasses; | ||
| 12 | |||
| 13 | |||
| 14 | public class F_ClassTree { | ||
| 15 | |||
| 16 | public class Level1 { | ||
| 17 | |||
| 18 | public int f1; | ||
| 19 | |||
| 20 | public class Level2 { | ||
| 21 | |||
| 22 | public int f2; | ||
| 23 | |||
| 24 | public class Level3 { | ||
| 25 | |||
| 26 | public int f3; | ||
| 27 | } | ||
| 28 | } | ||
| 29 | } | ||
| 30 | } | ||
diff --git a/src/test/java/cuchaz/enigma/inputs/loneClass/LoneClass.java b/src/test/java/cuchaz/enigma/inputs/loneClass/LoneClass.java new file mode 100644 index 00000000..bf264fa5 --- /dev/null +++ b/src/test/java/cuchaz/enigma/inputs/loneClass/LoneClass.java | |||
| @@ -0,0 +1,24 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.inputs.loneClass; | ||
| 12 | |||
| 13 | public class LoneClass { | ||
| 14 | |||
| 15 | private String m_name; | ||
| 16 | |||
| 17 | public LoneClass(String name) { | ||
| 18 | m_name = name; | ||
| 19 | } | ||
| 20 | |||
| 21 | public String getName() { | ||
| 22 | return m_name; | ||
| 23 | } | ||
| 24 | } | ||
diff --git a/src/test/java/cuchaz/enigma/inputs/translation/A_Basic.java b/src/test/java/cuchaz/enigma/inputs/translation/A_Basic.java new file mode 100644 index 00000000..26acac8a --- /dev/null +++ b/src/test/java/cuchaz/enigma/inputs/translation/A_Basic.java | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.inputs.translation; | ||
| 12 | |||
| 13 | public class A_Basic { | ||
| 14 | |||
| 15 | public int one; | ||
| 16 | public float two; | ||
| 17 | public String three; | ||
| 18 | |||
| 19 | public void m1() { | ||
| 20 | } | ||
| 21 | |||
| 22 | public int m2() { | ||
| 23 | return 42; | ||
| 24 | } | ||
| 25 | |||
| 26 | public void m3(int a1) { | ||
| 27 | } | ||
| 28 | |||
| 29 | public int m4(int a1) { | ||
| 30 | return 5; // chosen by fair die roll, guaranteed to be random | ||
| 31 | } | ||
| 32 | } | ||
diff --git a/src/test/java/cuchaz/enigma/inputs/translation/B_BaseClass.java b/src/test/java/cuchaz/enigma/inputs/translation/B_BaseClass.java new file mode 100644 index 00000000..035e3299 --- /dev/null +++ b/src/test/java/cuchaz/enigma/inputs/translation/B_BaseClass.java | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.inputs.translation; | ||
| 12 | |||
| 13 | public class B_BaseClass { | ||
| 14 | |||
| 15 | public int f1; | ||
| 16 | public char f2; | ||
| 17 | |||
| 18 | public int m1() { | ||
| 19 | return 5; | ||
| 20 | } | ||
| 21 | |||
| 22 | public int m2() { | ||
| 23 | return 42; | ||
| 24 | } | ||
| 25 | } | ||
diff --git a/src/test/java/cuchaz/enigma/inputs/translation/C_SubClass.java b/src/test/java/cuchaz/enigma/inputs/translation/C_SubClass.java new file mode 100644 index 00000000..6026a8d5 --- /dev/null +++ b/src/test/java/cuchaz/enigma/inputs/translation/C_SubClass.java | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.inputs.translation; | ||
| 12 | |||
| 13 | public class C_SubClass extends B_BaseClass { | ||
| 14 | |||
| 15 | public char f2; // shadows B_BaseClass.f2 | ||
| 16 | public int f3; | ||
| 17 | public int f4; | ||
| 18 | |||
| 19 | @Override | ||
| 20 | public int m1() { | ||
| 21 | return 32; | ||
| 22 | } | ||
| 23 | |||
| 24 | public int m3() { | ||
| 25 | return 7; | ||
| 26 | } | ||
| 27 | } | ||
diff --git a/src/test/java/cuchaz/enigma/inputs/translation/D_AnonymousTesting.java b/src/test/java/cuchaz/enigma/inputs/translation/D_AnonymousTesting.java new file mode 100644 index 00000000..a1827f98 --- /dev/null +++ b/src/test/java/cuchaz/enigma/inputs/translation/D_AnonymousTesting.java | |||
| @@ -0,0 +1,28 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.inputs.translation; | ||
| 12 | |||
| 13 | import java.util.ArrayList; | ||
| 14 | import java.util.List; | ||
| 15 | |||
| 16 | public class D_AnonymousTesting { | ||
| 17 | |||
| 18 | public List<Object> getObjs() { | ||
| 19 | List<Object> objs = new ArrayList<Object>(); | ||
| 20 | objs.add(new Object() { | ||
| 21 | @Override | ||
| 22 | public String toString() { | ||
| 23 | return "Object!"; | ||
| 24 | } | ||
| 25 | }); | ||
| 26 | return objs; | ||
| 27 | } | ||
| 28 | } | ||
diff --git a/src/test/java/cuchaz/enigma/inputs/translation/E_Bridges.java b/src/test/java/cuchaz/enigma/inputs/translation/E_Bridges.java new file mode 100644 index 00000000..769eb70e --- /dev/null +++ b/src/test/java/cuchaz/enigma/inputs/translation/E_Bridges.java | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.inputs.translation; | ||
| 12 | |||
| 13 | import java.util.Iterator; | ||
| 14 | |||
| 15 | |||
| 16 | public class E_Bridges implements Iterator<Object> { | ||
| 17 | |||
| 18 | @Override | ||
| 19 | public boolean hasNext() { | ||
| 20 | return false; | ||
| 21 | } | ||
| 22 | |||
| 23 | @Override | ||
| 24 | public String next() { | ||
| 25 | // the compiler will generate a bridge for this method | ||
| 26 | return "foo"; | ||
| 27 | } | ||
| 28 | |||
| 29 | @Override | ||
| 30 | public void remove() { | ||
| 31 | } | ||
| 32 | } | ||
diff --git a/src/test/java/cuchaz/enigma/inputs/translation/F_ObjectMethods.java b/src/test/java/cuchaz/enigma/inputs/translation/F_ObjectMethods.java new file mode 100644 index 00000000..32c246cb --- /dev/null +++ b/src/test/java/cuchaz/enigma/inputs/translation/F_ObjectMethods.java | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.inputs.translation; | ||
| 12 | |||
| 13 | public class F_ObjectMethods { | ||
| 14 | |||
| 15 | public void callEmAll() | ||
| 16 | throws Throwable { | ||
| 17 | clone(); | ||
| 18 | equals(this); | ||
| 19 | finalize(); | ||
| 20 | getClass(); | ||
| 21 | hashCode(); | ||
| 22 | notify(); | ||
| 23 | notifyAll(); | ||
| 24 | toString(); | ||
| 25 | wait(); | ||
| 26 | wait(0); | ||
| 27 | wait(0, 0); | ||
| 28 | } | ||
| 29 | } | ||
diff --git a/src/test/java/cuchaz/enigma/inputs/translation/G_OuterClass.java b/src/test/java/cuchaz/enigma/inputs/translation/G_OuterClass.java new file mode 100644 index 00000000..a2e0dafb --- /dev/null +++ b/src/test/java/cuchaz/enigma/inputs/translation/G_OuterClass.java | |||
| @@ -0,0 +1,36 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.inputs.translation; | ||
| 12 | |||
| 13 | |||
| 14 | public class G_OuterClass { | ||
| 15 | |||
| 16 | public class A_InnerClass { | ||
| 17 | |||
| 18 | public int f1; | ||
| 19 | public String f2; | ||
| 20 | |||
| 21 | public void m1() {} | ||
| 22 | |||
| 23 | public class A_InnerInnerClass { | ||
| 24 | |||
| 25 | public int f3; | ||
| 26 | |||
| 27 | public void m2() {} | ||
| 28 | } | ||
| 29 | } | ||
| 30 | |||
| 31 | public class B_NamelessClass { | ||
| 32 | public class A_NamedInnerClass { | ||
| 33 | public int f4; | ||
| 34 | } | ||
| 35 | } | ||
| 36 | } | ||
diff --git a/src/test/java/cuchaz/enigma/inputs/translation/H_NamelessClass.java b/src/test/java/cuchaz/enigma/inputs/translation/H_NamelessClass.java new file mode 100644 index 00000000..1b718a54 --- /dev/null +++ b/src/test/java/cuchaz/enigma/inputs/translation/H_NamelessClass.java | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.inputs.translation; | ||
| 12 | |||
| 13 | |||
| 14 | public class H_NamelessClass { | ||
| 15 | |||
| 16 | public class A_InnerClass { | ||
| 17 | |||
| 18 | public int f1; | ||
| 19 | public String f2; | ||
| 20 | |||
| 21 | public void m1() {} | ||
| 22 | |||
| 23 | public class A_InnerInnerClass { | ||
| 24 | |||
| 25 | public int f3; | ||
| 26 | |||
| 27 | public void m2() {} | ||
| 28 | } | ||
| 29 | } | ||
| 30 | |||
| 31 | public class B_NamelessClass { | ||
| 32 | public class A_NamedInnerClass { | ||
| 33 | public int f4; | ||
| 34 | public class A_AnotherInnerClass {} | ||
| 35 | public class B_YetAnotherInnerClass {} | ||
| 36 | } | ||
| 37 | } | ||
| 38 | } | ||
diff --git a/src/test/java/cuchaz/enigma/inputs/translation/I_Generics.java b/src/test/java/cuchaz/enigma/inputs/translation/I_Generics.java new file mode 100644 index 00000000..3490f9d9 --- /dev/null +++ b/src/test/java/cuchaz/enigma/inputs/translation/I_Generics.java | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.inputs.translation; | ||
| 12 | |||
| 13 | import java.util.List; | ||
| 14 | import java.util.Map; | ||
| 15 | |||
| 16 | |||
| 17 | public class I_Generics { | ||
| 18 | |||
| 19 | public class A_Type { | ||
| 20 | } | ||
| 21 | |||
| 22 | public List<Integer> f1; | ||
| 23 | public List<A_Type> f2; | ||
| 24 | public Map<A_Type,A_Type> f3; | ||
| 25 | |||
| 26 | public class B_Generic<T> { | ||
| 27 | public T f4; | ||
| 28 | public T m1() { | ||
| 29 | return null; | ||
| 30 | } | ||
| 31 | } | ||
| 32 | |||
| 33 | public B_Generic<Integer> f5; | ||
| 34 | public B_Generic<A_Type> f6; | ||
| 35 | } | ||
diff --git a/src/test/java/cuchaz/enigma/resources/translation.mappings b/src/test/java/cuchaz/enigma/resources/translation.mappings new file mode 100644 index 00000000..db78c19d --- /dev/null +++ b/src/test/java/cuchaz/enigma/resources/translation.mappings | |||
| @@ -0,0 +1,41 @@ | |||
| 1 | CLASS none/a deobf/A_Basic | ||
| 2 | FIELD a f1 I | ||
| 3 | FIELD a f2 F | ||
| 4 | FIELD a f3 Ljava/lang/String; | ||
| 5 | METHOD a m1 ()V | ||
| 6 | METHOD a m2 ()I | ||
| 7 | METHOD a m3 (I)V | ||
| 8 | METHOD a m4 (I)I | ||
| 9 | CLASS none/b deobf/B_BaseClass | ||
| 10 | FIELD a f1 I | ||
| 11 | FIELD a f2 C | ||
| 12 | METHOD a m1 ()I | ||
| 13 | METHOD b m2 ()I | ||
| 14 | CLASS none/c deobf/C_SubClass | ||
| 15 | FIELD b f2 C | ||
| 16 | FIELD b f3 I | ||
| 17 | FIELD c f4 I | ||
| 18 | METHOD a m1 ()I | ||
| 19 | METHOD c m3 ()I | ||
| 20 | CLASS none/g deobf/G_OuterClass | ||
| 21 | CLASS none/g$a A_InnerClass | ||
| 22 | CLASS none/g$a$a A_InnerInnerClass | ||
| 23 | FIELD a f3 I | ||
| 24 | METHOD a m2 ()V | ||
| 25 | FIELD a f1 I | ||
| 26 | FIELD a f2 Ljava/lang/String; | ||
| 27 | METHOD a m1 ()V | ||
| 28 | CLASS none/g$b | ||
| 29 | CLASS none/g$b$a A_NamedInnerClass | ||
| 30 | FIELD a f4 I | ||
| 31 | CLASS none/h | ||
| 32 | CLASS none/i deobf/I_Generics | ||
| 33 | CLASS none/i$a A_Type | ||
| 34 | CLASS none/i$b B_Generic | ||
| 35 | FIELD a f4 Ljava/lang/Object; | ||
| 36 | METHOD a m1 ()Ljava/lang/Object; | ||
| 37 | FIELD a f1 Ljava/util/List; | ||
| 38 | FIELD b f2 Ljava/util/List; | ||
| 39 | FIELD a f3 Ljava/util/Map; | ||
| 40 | FIELD a f5 Lnone/i$b; | ||
| 41 | FIELD b f6 Lnone/i$b; | ||