summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGravatar Michael Smith2015-05-21 23:30:00 +0100
committerGravatar Michael Smith2015-05-21 23:30:00 +0100
commite3f452250e51b7271f3989c7dfd12e4422934942 (patch)
tree5aa482f9a6e21eb318a3e23e7d8274d77c73faf6 /test
downloadenigma-fork-e3f452250e51b7271f3989c7dfd12e4422934942.tar.gz
enigma-fork-e3f452250e51b7271f3989c7dfd12e4422934942.tar.xz
enigma-fork-e3f452250e51b7271f3989c7dfd12e4422934942.zip
Support Gradle alongside SSJB
This makes builds faster, simpler and better automated but still keeps Cuchaz happy. :)
Diffstat (limited to 'test')
-rw-r--r--test/cuchaz/enigma/TestDeobfed.java95
-rw-r--r--test/cuchaz/enigma/TestDeobfuscator.java57
-rw-r--r--test/cuchaz/enigma/TestEntryFactory.java67
-rw-r--r--test/cuchaz/enigma/TestInnerClasses.java132
-rw-r--r--test/cuchaz/enigma/TestJarIndexConstructorReferences.java124
-rw-r--r--test/cuchaz/enigma/TestJarIndexInheritanceTree.java228
-rw-r--r--test/cuchaz/enigma/TestJarIndexLoneClass.java164
-rw-r--r--test/cuchaz/enigma/TestSignature.java268
-rw-r--r--test/cuchaz/enigma/TestSourceIndex.java67
-rw-r--r--test/cuchaz/enigma/TestTokensConstructors.java136
-rw-r--r--test/cuchaz/enigma/TestTranslator.java170
-rw-r--r--test/cuchaz/enigma/TestType.java243
-rw-r--r--test/cuchaz/enigma/TokenChecker.java65
-rw-r--r--test/cuchaz/enigma/inputs/Keep.java17
-rw-r--r--test/cuchaz/enigma/inputs/constructors/BaseClass.java25
-rw-r--r--test/cuchaz/enigma/inputs/constructors/Caller.java57
-rw-r--r--test/cuchaz/enigma/inputs/constructors/DefaultConstructable.java15
-rw-r--r--test/cuchaz/enigma/inputs/constructors/SubClass.java38
-rw-r--r--test/cuchaz/enigma/inputs/constructors/SubSubClass.java21
-rw-r--r--test/cuchaz/enigma/inputs/inheritanceTree/BaseClass.java31
-rw-r--r--test/cuchaz/enigma/inputs/inheritanceTree/SubclassA.java21
-rw-r--r--test/cuchaz/enigma/inputs/inheritanceTree/SubclassB.java40
-rw-r--r--test/cuchaz/enigma/inputs/inheritanceTree/SubsubclassAA.java34
-rw-r--r--test/cuchaz/enigma/inputs/innerClasses/A_Anonymous.java24
-rw-r--r--test/cuchaz/enigma/inputs/innerClasses/B_AnonymousWithScopeArgs.java23
-rw-r--r--test/cuchaz/enigma/inputs/innerClasses/C_ConstructorArgs.java30
-rw-r--r--test/cuchaz/enigma/inputs/innerClasses/D_Simple.java18
-rw-r--r--test/cuchaz/enigma/inputs/innerClasses/E_AnonymousWithOuterAccess.java31
-rw-r--r--test/cuchaz/enigma/inputs/innerClasses/F_ClassTree.java30
-rw-r--r--test/cuchaz/enigma/inputs/loneClass/LoneClass.java24
-rw-r--r--test/cuchaz/enigma/inputs/translation/A_Basic.java32
-rw-r--r--test/cuchaz/enigma/inputs/translation/B_BaseClass.java25
-rw-r--r--test/cuchaz/enigma/inputs/translation/C_SubClass.java27
-rw-r--r--test/cuchaz/enigma/inputs/translation/D_AnonymousTesting.java28
-rw-r--r--test/cuchaz/enigma/inputs/translation/E_Bridges.java32
-rw-r--r--test/cuchaz/enigma/inputs/translation/F_ObjectMethods.java29
-rw-r--r--test/cuchaz/enigma/inputs/translation/G_OuterClass.java36
-rw-r--r--test/cuchaz/enigma/inputs/translation/H_NamelessClass.java38
-rw-r--r--test/cuchaz/enigma/inputs/translation/I_Generics.java35
-rw-r--r--test/cuchaz/enigma/resources/translation.mappings41
40 files changed, 2618 insertions, 0 deletions
diff --git a/test/cuchaz/enigma/TestDeobfed.java b/test/cuchaz/enigma/TestDeobfed.java
new file mode 100644
index 0000000..5f3ef8c
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma;
12
13
14import static cuchaz.enigma.TestEntryFactory.*;
15import static org.hamcrest.MatcherAssert.*;
16import static org.hamcrest.Matchers.*;
17
18import java.util.jar.JarFile;
19
20import org.junit.BeforeClass;
21import org.junit.Test;
22
23import cuchaz.enigma.analysis.JarIndex;
24
25
26public 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/test/cuchaz/enigma/TestDeobfuscator.java b/test/cuchaz/enigma/TestDeobfuscator.java
new file mode 100644
index 0000000..1b0aa74
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma;
12
13import static org.junit.Assert.*;
14
15import java.io.IOException;
16import java.util.List;
17import java.util.jar.JarFile;
18
19import org.junit.Test;
20
21import com.google.common.collect.Lists;
22
23import cuchaz.enigma.mapping.ClassEntry;
24
25public 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/test/cuchaz/enigma/TestEntryFactory.java b/test/cuchaz/enigma/TestEntryFactory.java
new file mode 100644
index 0000000..4aa773b
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma;
12
13import cuchaz.enigma.analysis.EntryReference;
14import cuchaz.enigma.mapping.BehaviorEntry;
15import cuchaz.enigma.mapping.ClassEntry;
16import cuchaz.enigma.mapping.ConstructorEntry;
17import cuchaz.enigma.mapping.FieldEntry;
18import cuchaz.enigma.mapping.MethodEntry;
19import cuchaz.enigma.mapping.Signature;
20import cuchaz.enigma.mapping.Type;
21
22public 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/test/cuchaz/enigma/TestInnerClasses.java b/test/cuchaz/enigma/TestInnerClasses.java
new file mode 100644
index 0000000..a4f9021
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma;
12
13import static org.hamcrest.MatcherAssert.*;
14import static org.hamcrest.Matchers.*;
15
16import java.util.jar.JarFile;
17
18import org.junit.Test;
19
20import static cuchaz.enigma.TestEntryFactory.*;
21
22import cuchaz.enigma.analysis.JarIndex;
23import cuchaz.enigma.mapping.ClassEntry;
24
25public 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/test/cuchaz/enigma/TestJarIndexConstructorReferences.java b/test/cuchaz/enigma/TestJarIndexConstructorReferences.java
new file mode 100644
index 0000000..606801b
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma;
12
13import static cuchaz.enigma.TestEntryFactory.*;
14import static org.hamcrest.MatcherAssert.*;
15import static org.hamcrest.Matchers.*;
16
17import java.io.File;
18import java.util.Collection;
19import java.util.jar.JarFile;
20
21import org.junit.Test;
22
23import cuchaz.enigma.analysis.EntryReference;
24import cuchaz.enigma.analysis.JarIndex;
25import cuchaz.enigma.mapping.BehaviorEntry;
26import cuchaz.enigma.mapping.ClassEntry;
27
28public 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/test/cuchaz/enigma/TestJarIndexInheritanceTree.java b/test/cuchaz/enigma/TestJarIndexInheritanceTree.java
new file mode 100644
index 0000000..010f2dc
--- /dev/null
+++ b/test/cuchaz/enigma/TestJarIndexInheritanceTree.java
@@ -0,0 +1,228 @@
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 ******************************************************************************/
11package cuchaz.enigma;
12
13import static cuchaz.enigma.TestEntryFactory.*;
14import static org.hamcrest.MatcherAssert.*;
15import static org.hamcrest.Matchers.*;
16
17import java.util.Collection;
18import java.util.Set;
19import java.util.jar.JarFile;
20
21import org.junit.Test;
22
23import cuchaz.enigma.analysis.Access;
24import cuchaz.enigma.analysis.EntryReference;
25import cuchaz.enigma.analysis.JarIndex;
26import cuchaz.enigma.analysis.TranslationIndex;
27import cuchaz.enigma.mapping.BehaviorEntry;
28import cuchaz.enigma.mapping.ClassEntry;
29import cuchaz.enigma.mapping.FieldEntry;
30import cuchaz.enigma.mapping.MethodEntry;
31
32public class TestJarIndexInheritanceTree {
33
34 private JarIndex m_index;
35
36 private ClassEntry m_baseClass = newClass("none/a");
37 private ClassEntry m_subClassA = newClass("none/b");
38 private ClassEntry m_subClassAA = newClass("none/d");
39 private ClassEntry m_subClassB = newClass("none/c");
40 private FieldEntry m_nameField = newField(m_baseClass, "a", "Ljava/lang/String;");
41 private FieldEntry m_numThingsField = newField(m_subClassB, "a", "I");
42
43 public TestJarIndexInheritanceTree()
44 throws Exception {
45 m_index = new JarIndex();
46 m_index.indexJar(new JarFile("build/test-obf/inheritanceTree.jar"), false);
47 }
48
49 @Test
50 public void obfEntries() {
51 assertThat(m_index.getObfClassEntries(), containsInAnyOrder(
52 newClass("cuchaz/enigma/inputs/Keep"),
53 m_baseClass,
54 m_subClassA,
55 m_subClassAA,
56 m_subClassB
57 ));
58 }
59
60 @Test
61 public void translationIndex() {
62
63 TranslationIndex index = m_index.getTranslationIndex();
64
65 // base class
66 assertThat(index.getSuperclass(m_baseClass), is(nullValue()));
67 assertThat(index.getAncestry(m_baseClass), is(empty()));
68 assertThat(index.getSubclass(m_baseClass), containsInAnyOrder(
69 m_subClassA,
70 m_subClassB
71 ));
72
73 // subclass a
74 assertThat(index.getSuperclass(m_subClassA), is(m_baseClass));
75 assertThat(index.getAncestry(m_subClassA), contains(m_baseClass));
76 assertThat(index.getSubclass(m_subClassA), contains(m_subClassAA));
77
78 // subclass aa
79 assertThat(index.getSuperclass(m_subClassAA), is(m_subClassA));
80 assertThat(index.getAncestry(m_subClassAA), contains(m_subClassA, m_baseClass));
81 assertThat(index.getSubclass(m_subClassAA), is(empty()));
82
83 // subclass b
84 assertThat(index.getSuperclass(m_subClassB), is(m_baseClass));
85 assertThat(index.getAncestry(m_subClassB), contains(m_baseClass));
86 assertThat(index.getSubclass(m_subClassB), is(empty()));
87 }
88
89 @Test
90 public void access() {
91 assertThat(m_index.getAccess(m_nameField), is(Access.Private));
92 assertThat(m_index.getAccess(m_numThingsField), is(Access.Private));
93 }
94
95 @Test
96 public void relatedMethodImplementations() {
97
98 Set<MethodEntry> entries;
99
100 // getName()
101 entries = m_index.getRelatedMethodImplementations(newMethod(m_baseClass, "a", "()Ljava/lang/String;"));
102 assertThat(entries, containsInAnyOrder(
103 newMethod(m_baseClass, "a", "()Ljava/lang/String;"),
104 newMethod(m_subClassAA, "a", "()Ljava/lang/String;")
105 ));
106 entries = m_index.getRelatedMethodImplementations(newMethod(m_subClassAA, "a", "()Ljava/lang/String;"));
107 assertThat(entries, containsInAnyOrder(
108 newMethod(m_baseClass, "a", "()Ljava/lang/String;"),
109 newMethod(m_subClassAA, "a", "()Ljava/lang/String;")
110 ));
111
112 // doBaseThings()
113 entries = m_index.getRelatedMethodImplementations(newMethod(m_baseClass, "a", "()V"));
114 assertThat(entries, containsInAnyOrder(
115 newMethod(m_baseClass, "a", "()V"),
116 newMethod(m_subClassAA, "a", "()V"),
117 newMethod(m_subClassB, "a", "()V")
118 ));
119 entries = m_index.getRelatedMethodImplementations(newMethod(m_subClassAA, "a", "()V"));
120 assertThat(entries, containsInAnyOrder(
121 newMethod(m_baseClass, "a", "()V"),
122 newMethod(m_subClassAA, "a", "()V"),
123 newMethod(m_subClassB, "a", "()V")
124 ));
125 entries = m_index.getRelatedMethodImplementations(newMethod(m_subClassB, "a", "()V"));
126 assertThat(entries, containsInAnyOrder(
127 newMethod(m_baseClass, "a", "()V"),
128 newMethod(m_subClassAA, "a", "()V"),
129 newMethod(m_subClassB, "a", "()V")
130 ));
131
132 // doBThings
133 entries = m_index.getRelatedMethodImplementations(newMethod(m_subClassB, "b", "()V"));
134 assertThat(entries, containsInAnyOrder(newMethod(m_subClassB, "b", "()V")));
135 }
136
137 @Test
138 @SuppressWarnings("unchecked")
139 public void fieldReferences() {
140 Collection<EntryReference<FieldEntry,BehaviorEntry>> references;
141
142 // name
143 references = m_index.getFieldReferences(m_nameField);
144 assertThat(references, containsInAnyOrder(
145 newFieldReferenceByConstructor(m_nameField, m_baseClass.getName(), "(Ljava/lang/String;)V"),
146 newFieldReferenceByMethod(m_nameField, m_baseClass.getName(), "a", "()Ljava/lang/String;")
147 ));
148
149 // numThings
150 references = m_index.getFieldReferences(m_numThingsField);
151 assertThat(references, containsInAnyOrder(
152 newFieldReferenceByConstructor(m_numThingsField, m_subClassB.getName(), "()V"),
153 newFieldReferenceByMethod(m_numThingsField, m_subClassB.getName(), "b", "()V")
154 ));
155 }
156
157 @Test
158 @SuppressWarnings("unchecked")
159 public void behaviorReferences() {
160
161 BehaviorEntry source;
162 Collection<EntryReference<BehaviorEntry,BehaviorEntry>> references;
163
164 // baseClass constructor
165 source = newConstructor(m_baseClass, "(Ljava/lang/String;)V");
166 references = m_index.getBehaviorReferences(source);
167 assertThat(references, containsInAnyOrder(
168 newBehaviorReferenceByConstructor(source, m_subClassA.getName(), "(Ljava/lang/String;)V"),
169 newBehaviorReferenceByConstructor(source, m_subClassB.getName(), "()V")
170 ));
171
172 // subClassA constructor
173 source = newConstructor(m_subClassA, "(Ljava/lang/String;)V");
174 references = m_index.getBehaviorReferences(source);
175 assertThat(references, containsInAnyOrder(
176 newBehaviorReferenceByConstructor(source, m_subClassAA.getName(), "()V")
177 ));
178
179 // baseClass.getName()
180 source = newMethod(m_baseClass, "a", "()Ljava/lang/String;");
181 references = m_index.getBehaviorReferences(source);
182 assertThat(references, containsInAnyOrder(
183 newBehaviorReferenceByMethod(source, m_subClassAA.getName(), "a", "()Ljava/lang/String;"),
184 newBehaviorReferenceByMethod(source, m_subClassB.getName(), "a", "()V")
185 ));
186
187 // subclassAA.getName()
188 source = newMethod(m_subClassAA, "a", "()Ljava/lang/String;");
189 references = m_index.getBehaviorReferences(source);
190 assertThat(references, containsInAnyOrder(
191 newBehaviorReferenceByMethod(source, m_subClassAA.getName(), "a", "()V")
192 ));
193 }
194
195 @Test
196 public void containsEntries() {
197
198 // classes
199 assertThat(m_index.containsObfClass(m_baseClass), is(true));
200 assertThat(m_index.containsObfClass(m_subClassA), is(true));
201 assertThat(m_index.containsObfClass(m_subClassAA), is(true));
202 assertThat(m_index.containsObfClass(m_subClassB), is(true));
203
204 // fields
205 assertThat(m_index.containsObfField(m_nameField), is(true));
206 assertThat(m_index.containsObfField(m_numThingsField), is(true));
207
208 // methods
209 // getName()
210 assertThat(m_index.containsObfBehavior(newMethod(m_baseClass, "a", "()Ljava/lang/String;")), is(true));
211 assertThat(m_index.containsObfBehavior(newMethod(m_subClassA, "a", "()Ljava/lang/String;")), is(false));
212 assertThat(m_index.containsObfBehavior(newMethod(m_subClassAA, "a", "()Ljava/lang/String;")), is(true));
213 assertThat(m_index.containsObfBehavior(newMethod(m_subClassB, "a", "()Ljava/lang/String;")), is(false));
214
215 // doBaseThings()
216 assertThat(m_index.containsObfBehavior(newMethod(m_baseClass, "a", "()V")), is(true));
217 assertThat(m_index.containsObfBehavior(newMethod(m_subClassA, "a", "()V")), is(false));
218 assertThat(m_index.containsObfBehavior(newMethod(m_subClassAA, "a", "()V")), is(true));
219 assertThat(m_index.containsObfBehavior(newMethod(m_subClassB, "a", "()V")), is(true));
220
221 // doBThings()
222 assertThat(m_index.containsObfBehavior(newMethod(m_baseClass, "b", "()V")), is(false));
223 assertThat(m_index.containsObfBehavior(newMethod(m_subClassA, "b", "()V")), is(false));
224 assertThat(m_index.containsObfBehavior(newMethod(m_subClassAA, "b", "()V")), is(false));
225 assertThat(m_index.containsObfBehavior(newMethod(m_subClassB, "b", "()V")), is(true));
226
227 }
228}
diff --git a/test/cuchaz/enigma/TestJarIndexLoneClass.java b/test/cuchaz/enigma/TestJarIndexLoneClass.java
new file mode 100644
index 0000000..09479bb
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma;
12
13import static cuchaz.enigma.TestEntryFactory.*;
14import static org.hamcrest.MatcherAssert.*;
15import static org.hamcrest.Matchers.*;
16
17import java.util.Collection;
18import java.util.Set;
19import java.util.jar.JarFile;
20
21import org.junit.Test;
22
23import cuchaz.enigma.analysis.Access;
24import cuchaz.enigma.analysis.ClassImplementationsTreeNode;
25import cuchaz.enigma.analysis.ClassInheritanceTreeNode;
26import cuchaz.enigma.analysis.EntryReference;
27import cuchaz.enigma.analysis.JarIndex;
28import cuchaz.enigma.analysis.MethodInheritanceTreeNode;
29import cuchaz.enigma.mapping.BehaviorEntry;
30import cuchaz.enigma.mapping.ClassEntry;
31import cuchaz.enigma.mapping.FieldEntry;
32import cuchaz.enigma.mapping.MethodEntry;
33import cuchaz.enigma.mapping.Translator;
34
35public 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(nullValue()));
56 assertThat(m_index.getTranslationIndex().getSuperclass(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(nullValue()));
57 assertThat(m_index.getTranslationIndex().getAncestry(new ClassEntry("none/a")), is(empty()));
58 assertThat(m_index.getTranslationIndex().getAncestry(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(empty()));
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 contains() {
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/test/cuchaz/enigma/TestSignature.java b/test/cuchaz/enigma/TestSignature.java
new file mode 100644
index 0000000..8537adf
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma;
12
13import static org.hamcrest.MatcherAssert.*;
14import static org.hamcrest.Matchers.*;
15
16import org.junit.Test;
17
18import cuchaz.enigma.mapping.ClassNameReplacer;
19import cuchaz.enigma.mapping.Signature;
20import cuchaz.enigma.mapping.Type;
21
22
23public 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/test/cuchaz/enigma/TestSourceIndex.java b/test/cuchaz/enigma/TestSourceIndex.java
new file mode 100644
index 0000000..58d9ca9
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma;
12
13import java.io.File;
14import java.util.Set;
15import java.util.jar.JarFile;
16
17import org.junit.Test;
18
19import com.google.common.collect.Sets;
20import com.strobel.decompiler.languages.java.ast.CompilationUnit;
21
22import cuchaz.enigma.mapping.ClassEntry;
23
24public 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/test/cuchaz/enigma/TestTokensConstructors.java b/test/cuchaz/enigma/TestTokensConstructors.java
new file mode 100644
index 0000000..66c6fd1
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma;
12
13import static cuchaz.enigma.TestEntryFactory.*;
14import static org.hamcrest.MatcherAssert.*;
15import static org.hamcrest.Matchers.*;
16
17import java.util.jar.JarFile;
18
19import org.junit.Test;
20
21import cuchaz.enigma.mapping.BehaviorEntry;
22
23public 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/test/cuchaz/enigma/TestTranslator.java b/test/cuchaz/enigma/TestTranslator.java
new file mode 100644
index 0000000..9e58d25
--- /dev/null
+++ b/test/cuchaz/enigma/TestTranslator.java
@@ -0,0 +1,170 @@
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 ******************************************************************************/
11package cuchaz.enigma;
12
13import static cuchaz.enigma.TestEntryFactory.*;
14import static org.hamcrest.MatcherAssert.*;
15import static org.hamcrest.Matchers.*;
16
17import java.io.InputStream;
18import java.io.InputStreamReader;
19import java.util.jar.JarFile;
20
21import org.junit.BeforeClass;
22import org.junit.Test;
23
24import cuchaz.enigma.mapping.Entry;
25import cuchaz.enigma.mapping.Mappings;
26import cuchaz.enigma.mapping.MappingsReader;
27import cuchaz.enigma.mapping.TranslationDirection;
28import cuchaz.enigma.mapping.Translator;
29
30
31public 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 m_deobfuscator = new Deobfuscator(new JarFile("build/test-obf/translation.jar"));
42 try (InputStream in = TestTranslator.class.getResourceAsStream("/cuchaz/enigma/resources/translation.mappings")) {
43 m_mappings = new MappingsReader().read(new InputStreamReader(in));
44 m_deobfuscator.setMappings(m_mappings);
45 m_deobfTranslator = m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating);
46 m_obfTranslator = m_deobfuscator.getTranslator(TranslationDirection.Obfuscating);
47 }
48 }
49
50 @Test
51 public void basicClasses() {
52 assertMapping(newClass("none/a"), newClass("deobf/A_Basic"));
53 assertMapping(newClass("none/b"), newClass("deobf/B_BaseClass"));
54 assertMapping(newClass("none/c"), newClass("deobf/C_SubClass"));
55 }
56
57 @Test
58 public void basicFields() {
59 assertMapping(newField("none/a", "a", "I"), newField("deobf/A_Basic", "f1", "I"));
60 assertMapping(newField("none/a", "a", "F"), newField("deobf/A_Basic", "f2", "F"));
61 assertMapping(newField("none/a", "a", "Ljava/lang/String;"), newField("deobf/A_Basic", "f3", "Ljava/lang/String;"));
62 }
63
64 @Test
65 public void basicMethods() {
66 assertMapping(newMethod("none/a", "a", "()V"), newMethod("deobf/A_Basic", "m1", "()V"));
67 assertMapping(newMethod("none/a", "a", "()I"), newMethod("deobf/A_Basic", "m2", "()I"));
68 assertMapping(newMethod("none/a", "a", "(I)V"), newMethod("deobf/A_Basic", "m3", "(I)V"));
69 assertMapping(newMethod("none/a", "a", "(I)I"), newMethod("deobf/A_Basic", "m4", "(I)I"));
70 }
71
72 // TODO: basic constructors
73
74 @Test
75 public void inheritanceFields() {
76 assertMapping(newField("none/b", "a", "I"), newField("deobf/B_BaseClass", "f1", "I"));
77 assertMapping(newField("none/b", "a", "C"), newField("deobf/B_BaseClass", "f2", "C"));
78 assertMapping(newField("none/c", "b", "I"), newField("deobf/C_SubClass", "f3", "I"));
79 assertMapping(newField("none/c", "c", "I"), newField("deobf/C_SubClass", "f4", "I"));
80 }
81
82 @Test
83 public void inheritanceFieldsShadowing() {
84 assertMapping(newField("none/c", "b", "C"), newField("deobf/C_SubClass", "f2", "C"));
85 }
86
87 @Test
88 public void inheritanceFieldsBySubClass() {
89 assertMapping(newField("none/c", "a", "I"), newField("deobf/C_SubClass", "f1", "I"));
90 // NOTE: can't reference b.C by subclass since it's shadowed
91 }
92
93 @Test
94 public void inheritanceMethods() {
95 assertMapping(newMethod("none/b", "a", "()I"), newMethod("deobf/B_BaseClass", "m1", "()I"));
96 assertMapping(newMethod("none/b", "b", "()I"), newMethod("deobf/B_BaseClass", "m2", "()I"));
97 assertMapping(newMethod("none/c", "c", "()I"), newMethod("deobf/C_SubClass", "m3", "()I"));
98 }
99
100 @Test
101 public void inheritanceMethodsOverrides() {
102 assertMapping(newMethod("none/c", "a", "()I"), newMethod("deobf/C_SubClass", "m1", "()I"));
103 }
104
105 @Test
106 public void inheritanceMethodsBySubClass() {
107 assertMapping(newMethod("none/c", "b", "()I"), newMethod("deobf/C_SubClass", "m2", "()I"));
108 }
109
110 @Test
111 public void innerClasses() {
112
113 // classes
114 assertMapping(newClass("none/g"), newClass("deobf/G_OuterClass"));
115 assertMapping(newClass("none/g$a"), newClass("deobf/G_OuterClass$A_InnerClass"));
116 assertMapping(newClass("none/g$a$a"), newClass("deobf/G_OuterClass$A_InnerClass$A_InnerInnerClass"));
117 assertMapping(newClass("none/g$b"), newClass("deobf/G_OuterClass$b"));
118 assertMapping(newClass("none/g$b$a"), newClass("deobf/G_OuterClass$b$A_NamedInnerClass"));
119
120 // fields
121 assertMapping(newField("none/g$a", "a", "I"), newField("deobf/G_OuterClass$A_InnerClass", "f1", "I"));
122 assertMapping(newField("none/g$a", "a", "Ljava/lang/String;"), newField("deobf/G_OuterClass$A_InnerClass", "f2", "Ljava/lang/String;"));
123 assertMapping(newField("none/g$a$a", "a", "I"), newField("deobf/G_OuterClass$A_InnerClass$A_InnerInnerClass", "f3", "I"));
124 assertMapping(newField("none/g$b$a", "a", "I"), newField("deobf/G_OuterClass$b$A_NamedInnerClass", "f4", "I"));
125
126 // methods
127 assertMapping(newMethod("none/g$a", "a", "()V"), newMethod("deobf/G_OuterClass$A_InnerClass", "m1", "()V"));
128 assertMapping(newMethod("none/g$a$a", "a", "()V"), newMethod("deobf/G_OuterClass$A_InnerClass$A_InnerInnerClass", "m2", "()V"));
129 }
130
131 @Test
132 public void namelessClass() {
133 assertMapping(newClass("none/h"), newClass("none/h"));
134 }
135
136 @Test
137 public void testGenerics() {
138
139 // classes
140 assertMapping(newClass("none/i"), newClass("deobf/I_Generics"));
141 assertMapping(newClass("none/i$a"), newClass("deobf/I_Generics$A_Type"));
142 assertMapping(newClass("none/i$b"), newClass("deobf/I_Generics$B_Generic"));
143
144 // fields
145 assertMapping(newField("none/i", "a", "Ljava/util/List;"), newField("deobf/I_Generics", "f1", "Ljava/util/List;"));
146 assertMapping(newField("none/i", "b", "Ljava/util/List;"), newField("deobf/I_Generics", "f2", "Ljava/util/List;"));
147 assertMapping(newField("none/i", "a", "Ljava/util/Map;"), newField("deobf/I_Generics", "f3", "Ljava/util/Map;"));
148 assertMapping(newField("none/i$b", "a", "Ljava/lang/Object;"), newField("deobf/I_Generics$B_Generic", "f4", "Ljava/lang/Object;"));
149 assertMapping(newField("none/i", "a", "Lnone/i$b;"), newField("deobf/I_Generics", "f5", "Ldeobf/I_Generics$B_Generic;"));
150 assertMapping(newField("none/i", "b", "Lnone/i$b;"), newField("deobf/I_Generics", "f6", "Ldeobf/I_Generics$B_Generic;"));
151
152 // methods
153 assertMapping(newMethod("none/i$b", "a", "()Ljava/lang/Object;"), newMethod("deobf/I_Generics$B_Generic", "m1", "()Ljava/lang/Object;"));
154 }
155
156 private void assertMapping(Entry obf, Entry deobf) {
157 assertThat(m_deobfTranslator.translateEntry(obf), is(deobf));
158 assertThat(m_obfTranslator.translateEntry(deobf), is(obf));
159
160 String deobfName = m_deobfTranslator.translate(obf);
161 if (deobfName != null) {
162 assertThat(deobfName, is(deobf.getName()));
163 }
164
165 String obfName = m_obfTranslator.translate(deobf);
166 if (obfName != null) {
167 assertThat(obfName, is(obf.getName()));
168 }
169 }
170}
diff --git a/test/cuchaz/enigma/TestType.java b/test/cuchaz/enigma/TestType.java
new file mode 100644
index 0000000..01c235b
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma;
12
13import static cuchaz.enigma.TestEntryFactory.*;
14import static org.hamcrest.MatcherAssert.*;
15import static org.hamcrest.Matchers.*;
16
17import org.junit.Test;
18
19import cuchaz.enigma.mapping.Type;
20
21
22public 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/test/cuchaz/enigma/TokenChecker.java b/test/cuchaz/enigma/TokenChecker.java
new file mode 100644
index 0000000..7afb4cf
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma;
12
13import java.io.IOException;
14import java.util.Collection;
15import java.util.List;
16import java.util.jar.JarFile;
17
18import com.google.common.collect.Lists;
19import com.strobel.decompiler.languages.java.ast.CompilationUnit;
20
21import cuchaz.enigma.analysis.EntryReference;
22import cuchaz.enigma.analysis.SourceIndex;
23import cuchaz.enigma.analysis.Token;
24import cuchaz.enigma.mapping.Entry;
25
26public class TokenChecker {
27
28 private Deobfuscator m_deobfuscator;
29
30 protected TokenChecker(JarFile jarFile)
31 throws IOException {
32 m_deobfuscator = new Deobfuscator(jarFile);
33 }
34
35 protected String getDeclarationToken(Entry entry) {
36 // decompile the class
37 CompilationUnit tree = m_deobfuscator.getSourceTree(entry.getClassName());
38 // DEBUG
39 // tree.acceptVisitor( new TreeDumpVisitor( new File( "tree." + entry.getClassName().replace( '/', '.' ) + ".txt" ) ), null );
40 String source = m_deobfuscator.getSource(tree);
41 SourceIndex index = m_deobfuscator.getSourceIndex(tree, source);
42
43 // get the token value
44 Token token = index.getDeclarationToken(entry);
45 if (token == null) {
46 return null;
47 }
48 return source.substring(token.start, token.end);
49 }
50
51 @SuppressWarnings("unchecked")
52 protected Collection<String> getReferenceTokens(EntryReference<? extends Entry,? extends Entry> reference) {
53 // decompile the class
54 CompilationUnit tree = m_deobfuscator.getSourceTree(reference.context.getClassName());
55 String source = m_deobfuscator.getSource(tree);
56 SourceIndex index = m_deobfuscator.getSourceIndex(tree, source);
57
58 // get the token values
59 List<String> values = Lists.newArrayList();
60 for (Token token : index.getReferenceTokens((EntryReference<Entry,Entry>)reference)) {
61 values.add(source.substring(token.start, token.end));
62 }
63 return values;
64 }
65}
diff --git a/test/cuchaz/enigma/inputs/Keep.java b/test/cuchaz/enigma/inputs/Keep.java
new file mode 100644
index 0000000..f04875f
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma.inputs;
12
13public class Keep {
14 public static void main(String[] args) {
15 System.out.println("Keep me!");
16 }
17}
diff --git a/test/cuchaz/enigma/inputs/constructors/BaseClass.java b/test/cuchaz/enigma/inputs/constructors/BaseClass.java
new file mode 100644
index 0000000..65e782a
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma.inputs.constructors;
12
13// none/a
14public 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/test/cuchaz/enigma/inputs/constructors/Caller.java b/test/cuchaz/enigma/inputs/constructors/Caller.java
new file mode 100644
index 0000000..75096ec
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma.inputs.constructors;
12
13// none/b
14public 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/test/cuchaz/enigma/inputs/constructors/DefaultConstructable.java b/test/cuchaz/enigma/inputs/constructors/DefaultConstructable.java
new file mode 100644
index 0000000..655f4da
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma.inputs.constructors;
12
13public class DefaultConstructable {
14 // only default constructor
15}
diff --git a/test/cuchaz/enigma/inputs/constructors/SubClass.java b/test/cuchaz/enigma/inputs/constructors/SubClass.java
new file mode 100644
index 0000000..b0fb3e9
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma.inputs.constructors;
12
13// none/d extends none/a
14public 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/test/cuchaz/enigma/inputs/constructors/SubSubClass.java b/test/cuchaz/enigma/inputs/constructors/SubSubClass.java
new file mode 100644
index 0000000..5031405
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma.inputs.constructors;
12
13// none/e extends none/d
14public 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/test/cuchaz/enigma/inputs/inheritanceTree/BaseClass.java b/test/cuchaz/enigma/inputs/inheritanceTree/BaseClass.java
new file mode 100644
index 0000000..4f9c5b0
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma.inputs.inheritanceTree;
12
13// none/a
14public 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/test/cuchaz/enigma/inputs/inheritanceTree/SubclassA.java b/test/cuchaz/enigma/inputs/inheritanceTree/SubclassA.java
new file mode 100644
index 0000000..140d2a8
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma.inputs.inheritanceTree;
12
13// none/b extends none/a
14public 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/test/cuchaz/enigma/inputs/inheritanceTree/SubclassB.java b/test/cuchaz/enigma/inputs/inheritanceTree/SubclassB.java
new file mode 100644
index 0000000..99d149b
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma.inputs.inheritanceTree;
12
13// none/c extends none/a
14public 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/test/cuchaz/enigma/inputs/inheritanceTree/SubsubclassAA.java b/test/cuchaz/enigma/inputs/inheritanceTree/SubsubclassAA.java
new file mode 100644
index 0000000..2e414b7
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma.inputs.inheritanceTree;
12
13// none/d extends none/b
14public 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/test/cuchaz/enigma/inputs/innerClasses/A_Anonymous.java b/test/cuchaz/enigma/inputs/innerClasses/A_Anonymous.java
new file mode 100644
index 0000000..f644439
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma.inputs.innerClasses;
12
13public 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/test/cuchaz/enigma/inputs/innerClasses/B_AnonymousWithScopeArgs.java b/test/cuchaz/enigma/inputs/innerClasses/B_AnonymousWithScopeArgs.java
new file mode 100644
index 0000000..d78be84
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma.inputs.innerClasses;
12
13public 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/test/cuchaz/enigma/inputs/innerClasses/C_ConstructorArgs.java b/test/cuchaz/enigma/inputs/innerClasses/C_ConstructorArgs.java
new file mode 100644
index 0000000..eb03489
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma.inputs.innerClasses;
12
13@SuppressWarnings("unused")
14public 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/test/cuchaz/enigma/inputs/innerClasses/D_Simple.java b/test/cuchaz/enigma/inputs/innerClasses/D_Simple.java
new file mode 100644
index 0000000..0e9bf82
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma.inputs.innerClasses;
12
13public class D_Simple {
14
15 class Inner {
16 // nothing to do
17 }
18}
diff --git a/test/cuchaz/enigma/inputs/innerClasses/E_AnonymousWithOuterAccess.java b/test/cuchaz/enigma/inputs/innerClasses/E_AnonymousWithOuterAccess.java
new file mode 100644
index 0000000..255434d
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma.inputs.innerClasses;
12
13public 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/test/cuchaz/enigma/inputs/innerClasses/F_ClassTree.java b/test/cuchaz/enigma/inputs/innerClasses/F_ClassTree.java
new file mode 100644
index 0000000..7d1dab4
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma.inputs.innerClasses;
12
13
14public 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/test/cuchaz/enigma/inputs/loneClass/LoneClass.java b/test/cuchaz/enigma/inputs/loneClass/LoneClass.java
new file mode 100644
index 0000000..bf264fa
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma.inputs.loneClass;
12
13public 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/test/cuchaz/enigma/inputs/translation/A_Basic.java b/test/cuchaz/enigma/inputs/translation/A_Basic.java
new file mode 100644
index 0000000..26acac8
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma.inputs.translation;
12
13public 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/test/cuchaz/enigma/inputs/translation/B_BaseClass.java b/test/cuchaz/enigma/inputs/translation/B_BaseClass.java
new file mode 100644
index 0000000..035e329
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma.inputs.translation;
12
13public 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/test/cuchaz/enigma/inputs/translation/C_SubClass.java b/test/cuchaz/enigma/inputs/translation/C_SubClass.java
new file mode 100644
index 0000000..6026a8d
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma.inputs.translation;
12
13public 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/test/cuchaz/enigma/inputs/translation/D_AnonymousTesting.java b/test/cuchaz/enigma/inputs/translation/D_AnonymousTesting.java
new file mode 100644
index 0000000..a1827f9
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma.inputs.translation;
12
13import java.util.ArrayList;
14import java.util.List;
15
16public 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/test/cuchaz/enigma/inputs/translation/E_Bridges.java b/test/cuchaz/enigma/inputs/translation/E_Bridges.java
new file mode 100644
index 0000000..769eb70
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma.inputs.translation;
12
13import java.util.Iterator;
14
15
16public 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/test/cuchaz/enigma/inputs/translation/F_ObjectMethods.java b/test/cuchaz/enigma/inputs/translation/F_ObjectMethods.java
new file mode 100644
index 0000000..32c246c
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma.inputs.translation;
12
13public 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/test/cuchaz/enigma/inputs/translation/G_OuterClass.java b/test/cuchaz/enigma/inputs/translation/G_OuterClass.java
new file mode 100644
index 0000000..a2e0daf
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma.inputs.translation;
12
13
14public 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/test/cuchaz/enigma/inputs/translation/H_NamelessClass.java b/test/cuchaz/enigma/inputs/translation/H_NamelessClass.java
new file mode 100644
index 0000000..1b718a5
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma.inputs.translation;
12
13
14public 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/test/cuchaz/enigma/inputs/translation/I_Generics.java b/test/cuchaz/enigma/inputs/translation/I_Generics.java
new file mode 100644
index 0000000..3490f9d
--- /dev/null
+++ b/test/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 ******************************************************************************/
11package cuchaz.enigma.inputs.translation;
12
13import java.util.List;
14import java.util.Map;
15
16
17public 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/test/cuchaz/enigma/resources/translation.mappings b/test/cuchaz/enigma/resources/translation.mappings
new file mode 100644
index 0000000..db78c19
--- /dev/null
+++ b/test/cuchaz/enigma/resources/translation.mappings
@@ -0,0 +1,41 @@
1CLASS 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
9CLASS 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
14CLASS 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
20CLASS 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
31CLASS none/h
32CLASS 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;