From ed9b5cdfc648e86fd463bfa8d86b94c41671e14c Mon Sep 17 00:00:00 2001 From: jeff Date: Sun, 8 Feb 2015 21:29:25 -0500 Subject: switch all classes to new signature/type system --- test/cuchaz/enigma/EntryFactory.java | 67 ++++++ test/cuchaz/enigma/TestDeobfuscator.java | 58 +++++ test/cuchaz/enigma/TestInnerClasses.java | 90 +++++++ .../enigma/TestJarIndexConstructorReferences.java | 124 ++++++++++ .../cuchaz/enigma/TestJarIndexInheritanceTree.java | 228 ++++++++++++++++++ test/cuchaz/enigma/TestJarIndexLoneClass.java | 165 +++++++++++++ test/cuchaz/enigma/TestSignature.java | 266 +++++++++++++++++++++ test/cuchaz/enigma/TestSourceIndex.java | 50 ++++ test/cuchaz/enigma/TestTokensConstructors.java | 136 +++++++++++ test/cuchaz/enigma/TestTranslator.java | 39 +++ test/cuchaz/enigma/TestType.java | 229 ++++++++++++++++++ test/cuchaz/enigma/TokenChecker.java | 65 +++++ test/cuchaz/enigma/inputs/Keep.java | 7 + .../enigma/inputs/constructors/BaseClass.java | 15 ++ test/cuchaz/enigma/inputs/constructors/Caller.java | 47 ++++ .../inputs/constructors/DefaultConstructable.java | 5 + .../enigma/inputs/constructors/SubClass.java | 28 +++ .../enigma/inputs/constructors/SubSubClass.java | 11 + .../enigma/inputs/inheritanceTree/BaseClass.java | 21 ++ .../enigma/inputs/inheritanceTree/SubclassA.java | 11 + .../enigma/inputs/inheritanceTree/SubclassB.java | 30 +++ .../inputs/inheritanceTree/SubsubclassAA.java | 24 ++ .../enigma/inputs/innerClasses/A_Anonymous.java | 14 ++ .../innerClasses/B_AnonymousWithScopeArgs.java | 13 + .../inputs/innerClasses/C_ConstructorArgs.java | 20 ++ .../enigma/inputs/innerClasses/D_Simple.java | 8 + .../innerClasses/E_AnonymousWithOuterAccess.java | 21 ++ test/cuchaz/enigma/inputs/loneClass/LoneClass.java | 14 ++ test/cuchaz/enigma/inputs/translation/A.java | 8 + test/cuchaz/enigma/resources/translation.mappings | 4 + 30 files changed, 1818 insertions(+) create mode 100644 test/cuchaz/enigma/EntryFactory.java create mode 100644 test/cuchaz/enigma/TestDeobfuscator.java create mode 100644 test/cuchaz/enigma/TestInnerClasses.java create mode 100644 test/cuchaz/enigma/TestJarIndexConstructorReferences.java create mode 100644 test/cuchaz/enigma/TestJarIndexInheritanceTree.java create mode 100644 test/cuchaz/enigma/TestJarIndexLoneClass.java create mode 100644 test/cuchaz/enigma/TestSignature.java create mode 100644 test/cuchaz/enigma/TestSourceIndex.java create mode 100644 test/cuchaz/enigma/TestTokensConstructors.java create mode 100644 test/cuchaz/enigma/TestTranslator.java create mode 100644 test/cuchaz/enigma/TestType.java create mode 100644 test/cuchaz/enigma/TokenChecker.java create mode 100644 test/cuchaz/enigma/inputs/Keep.java create mode 100644 test/cuchaz/enigma/inputs/constructors/BaseClass.java create mode 100644 test/cuchaz/enigma/inputs/constructors/Caller.java create mode 100644 test/cuchaz/enigma/inputs/constructors/DefaultConstructable.java create mode 100644 test/cuchaz/enigma/inputs/constructors/SubClass.java create mode 100644 test/cuchaz/enigma/inputs/constructors/SubSubClass.java create mode 100644 test/cuchaz/enigma/inputs/inheritanceTree/BaseClass.java create mode 100644 test/cuchaz/enigma/inputs/inheritanceTree/SubclassA.java create mode 100644 test/cuchaz/enigma/inputs/inheritanceTree/SubclassB.java create mode 100644 test/cuchaz/enigma/inputs/inheritanceTree/SubsubclassAA.java create mode 100644 test/cuchaz/enigma/inputs/innerClasses/A_Anonymous.java create mode 100644 test/cuchaz/enigma/inputs/innerClasses/B_AnonymousWithScopeArgs.java create mode 100644 test/cuchaz/enigma/inputs/innerClasses/C_ConstructorArgs.java create mode 100644 test/cuchaz/enigma/inputs/innerClasses/D_Simple.java create mode 100644 test/cuchaz/enigma/inputs/innerClasses/E_AnonymousWithOuterAccess.java create mode 100644 test/cuchaz/enigma/inputs/loneClass/LoneClass.java create mode 100644 test/cuchaz/enigma/inputs/translation/A.java create mode 100644 test/cuchaz/enigma/resources/translation.mappings (limited to 'test') diff --git a/test/cuchaz/enigma/EntryFactory.java b/test/cuchaz/enigma/EntryFactory.java new file mode 100644 index 00000000..fa90779d --- /dev/null +++ b/test/cuchaz/enigma/EntryFactory.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2014 Jeff Martin.\ + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Public License v3.0 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/gpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ +package cuchaz.enigma; + +import cuchaz.enigma.analysis.EntryReference; +import cuchaz.enigma.mapping.BehaviorEntry; +import cuchaz.enigma.mapping.ClassEntry; +import cuchaz.enigma.mapping.ConstructorEntry; +import cuchaz.enigma.mapping.FieldEntry; +import cuchaz.enigma.mapping.MethodEntry; +import cuchaz.enigma.mapping.Signature; + +public class EntryFactory { + + public static ClassEntry newClass(String name) { + return new ClassEntry(name); + } + + public static FieldEntry newField(String className, String fieldName) { + return newField(newClass(className), fieldName); + } + + public static FieldEntry newField(ClassEntry classEntry, String fieldName) { + return new FieldEntry(classEntry, fieldName); + } + + public static MethodEntry newMethod(String className, String methodName, String methodSignature) { + return newMethod(newClass(className), methodName, methodSignature); + } + + public static MethodEntry newMethod(ClassEntry classEntry, String methodName, String methodSignature) { + return new MethodEntry(classEntry, methodName, new Signature(methodSignature)); + } + + public static ConstructorEntry newConstructor(String className, String signature) { + return newConstructor(newClass(className), signature); + } + + public static ConstructorEntry newConstructor(ClassEntry classEntry, String signature) { + return new ConstructorEntry(classEntry, new Signature(signature)); + } + + public static EntryReference newFieldReferenceByMethod(FieldEntry fieldEntry, String callerClassName, String callerName, String callerSignature) { + return new EntryReference(fieldEntry, "", newMethod(callerClassName, callerName, callerSignature)); + } + + public static EntryReference newFieldReferenceByConstructor(FieldEntry fieldEntry, String callerClassName, String callerSignature) { + return new EntryReference(fieldEntry, "", newConstructor(callerClassName, callerSignature)); + } + + public static EntryReference newBehaviorReferenceByMethod(BehaviorEntry behaviorEntry, String callerClassName, String callerName, String callerSignature) { + return new EntryReference(behaviorEntry, "", newMethod(callerClassName, callerName, callerSignature)); + } + + public static EntryReference newBehaviorReferenceByConstructor(BehaviorEntry behaviorEntry, String callerClassName, String callerSignature) { + return new EntryReference(behaviorEntry, "", newConstructor(callerClassName, callerSignature)); + } +} diff --git a/test/cuchaz/enigma/TestDeobfuscator.java b/test/cuchaz/enigma/TestDeobfuscator.java new file mode 100644 index 00000000..26d492d8 --- /dev/null +++ b/test/cuchaz/enigma/TestDeobfuscator.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * Copyright (c) 2014 Jeff Martin.\ + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Public License v3.0 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/gpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ +package cuchaz.enigma; + +import static org.junit.Assert.*; + +import java.io.IOException; +import java.util.List; +import java.util.jar.JarFile; + +import org.junit.Test; + +import com.google.common.collect.Lists; + +import cuchaz.enigma.mapping.ClassEntry; + +public class TestDeobfuscator { + + private Deobfuscator getDeobfuscator() + throws IOException { + return new Deobfuscator(new JarFile("build/testLoneClass.obf.jar")); + } + + @Test + public void loadJar() + throws Exception { + getDeobfuscator(); + } + + @Test + public void getClasses() + throws Exception { + Deobfuscator deobfuscator = getDeobfuscator(); + List obfClasses = Lists.newArrayList(); + List deobfClasses = Lists.newArrayList(); + deobfuscator.getSeparatedClasses(obfClasses, deobfClasses); + assertEquals(1, obfClasses.size()); + assertEquals("none/a", obfClasses.get(0).getName()); + assertEquals(1, deobfClasses.size()); + assertEquals("cuchaz/enigma/inputs/Keep", deobfClasses.get(0).getName()); + } + + @Test + public void decompileClass() + throws Exception { + Deobfuscator deobfuscator = getDeobfuscator(); + deobfuscator.getSource(deobfuscator.getSourceTree("none/a")); + } +} diff --git a/test/cuchaz/enigma/TestInnerClasses.java b/test/cuchaz/enigma/TestInnerClasses.java new file mode 100644 index 00000000..2e16a330 --- /dev/null +++ b/test/cuchaz/enigma/TestInnerClasses.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2014 Jeff Martin. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Public License v3.0 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/gpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ +package cuchaz.enigma; + +import static org.hamcrest.MatcherAssert.*; +import static org.hamcrest.Matchers.*; + +import java.util.jar.JarFile; + +import org.junit.Test; + +import cuchaz.enigma.analysis.JarIndex; + +public class TestInnerClasses { + + private JarIndex m_index; + private Deobfuscator m_deobfuscator; + + private static final String AnonymousOuter = "none/a"; + private static final String AnonymousInner = "b"; + private static final String SimpleOuter = "none/g"; + private static final String SimpleInner = "h"; + private static final String ConstructorArgsOuter = "none/e"; + private static final String ConstructorArgsInner = "f"; + private static final String AnonymousWithScopeArgsOuter = "none/c"; + private static final String AnonymousWithScopeArgsInner = "d"; + private static final String AnonymousWithOuterAccessOuter = "none/i"; + private static final String AnonymousWithOuterAccessInner = "j"; + + public TestInnerClasses() + throws Exception { + m_index = new JarIndex(); + JarFile jar = new JarFile("build/testInnerClasses.obf.jar"); + m_index.indexJar(jar, true); + m_deobfuscator = new Deobfuscator(jar); + } + + @Test + public void simple() { + assertThat(m_index.getOuterClass(SimpleInner), is(SimpleOuter)); + assertThat(m_index.getInnerClasses(SimpleOuter), containsInAnyOrder(SimpleInner)); + assertThat(m_index.isAnonymousClass(SimpleInner), is(false)); + decompile(SimpleOuter); + } + + @Test + public void anonymous() { + assertThat(m_index.getOuterClass(AnonymousInner), is(AnonymousOuter)); + assertThat(m_index.getInnerClasses(AnonymousOuter), containsInAnyOrder(AnonymousInner)); + assertThat(m_index.isAnonymousClass(AnonymousInner), is(true)); + decompile(AnonymousOuter); + } + + @Test + public void constructorArgs() { + assertThat(m_index.getOuterClass(ConstructorArgsInner), is(ConstructorArgsOuter)); + assertThat(m_index.getInnerClasses(ConstructorArgsOuter), containsInAnyOrder(ConstructorArgsInner)); + assertThat(m_index.isAnonymousClass(ConstructorArgsInner), is(false)); + decompile(ConstructorArgsOuter); + } + + @Test + public void anonymousWithScopeArgs() { + assertThat(m_index.getOuterClass(AnonymousWithScopeArgsInner), is(AnonymousWithScopeArgsOuter)); + assertThat(m_index.getInnerClasses(AnonymousWithScopeArgsOuter), containsInAnyOrder(AnonymousWithScopeArgsInner)); + assertThat(m_index.isAnonymousClass(AnonymousWithScopeArgsInner), is(true)); + decompile(AnonymousWithScopeArgsOuter); + } + + @Test + public void anonymousWithOuterAccess() { + assertThat(m_index.getOuterClass(AnonymousWithOuterAccessInner), is(AnonymousWithOuterAccessOuter)); + assertThat(m_index.getInnerClasses(AnonymousWithOuterAccessOuter), containsInAnyOrder(AnonymousWithOuterAccessInner)); + assertThat(m_index.isAnonymousClass(AnonymousWithOuterAccessInner), is(true)); + decompile(AnonymousWithOuterAccessOuter); + } + + private void decompile(String name) { + m_deobfuscator.getSourceTree(name); + } +} diff --git a/test/cuchaz/enigma/TestJarIndexConstructorReferences.java b/test/cuchaz/enigma/TestJarIndexConstructorReferences.java new file mode 100644 index 00000000..22812fea --- /dev/null +++ b/test/cuchaz/enigma/TestJarIndexConstructorReferences.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * Copyright (c) 2014 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Public License v3.0 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/gpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ +package cuchaz.enigma; + +import static cuchaz.enigma.EntryFactory.*; +import static org.hamcrest.MatcherAssert.*; +import static org.hamcrest.Matchers.*; + +import java.io.File; +import java.util.Collection; +import java.util.jar.JarFile; + +import org.junit.Test; + +import cuchaz.enigma.analysis.EntryReference; +import cuchaz.enigma.analysis.JarIndex; +import cuchaz.enigma.mapping.BehaviorEntry; +import cuchaz.enigma.mapping.ClassEntry; + +public class TestJarIndexConstructorReferences { + + private JarIndex m_index; + + private ClassEntry m_baseClass = newClass("none/a"); + private ClassEntry m_subClass = newClass("none/d"); + private ClassEntry m_subsubClass = newClass("none/e"); + private ClassEntry m_defaultClass = newClass("none/c"); + private ClassEntry m_callerClass = newClass("none/b"); + + public TestJarIndexConstructorReferences() + throws Exception { + File jarFile = new File("build/testConstructors.obf.jar"); + m_index = new JarIndex(); + m_index.indexJar(new JarFile(jarFile), false); + } + + @Test + public void obfEntries() { + assertThat(m_index.getObfClassEntries(), containsInAnyOrder(newClass("cuchaz/enigma/inputs/Keep"), m_baseClass, m_subClass, m_subsubClass, m_defaultClass, m_callerClass)); + } + + @Test + @SuppressWarnings("unchecked") + public void baseDefault() { + BehaviorEntry source = newConstructor(m_baseClass, "()V"); + Collection> references = m_index.getBehaviorReferences(source); + assertThat(references, containsInAnyOrder( + newBehaviorReferenceByMethod(source, m_callerClass.getName(), "a", "()V"), + newBehaviorReferenceByConstructor(source, m_subClass.getName(), "()V"), + newBehaviorReferenceByConstructor(source, m_subClass.getName(), "(III)V") + )); + } + + @Test + @SuppressWarnings("unchecked") + public void baseInt() { + BehaviorEntry source = newConstructor(m_baseClass, "(I)V"); + assertThat(m_index.getBehaviorReferences(source), containsInAnyOrder( + newBehaviorReferenceByMethod(source, m_callerClass.getName(), "b", "()V") + )); + } + + @Test + @SuppressWarnings("unchecked") + public void subDefault() { + BehaviorEntry source = newConstructor(m_subClass, "()V"); + assertThat(m_index.getBehaviorReferences(source), containsInAnyOrder( + newBehaviorReferenceByMethod(source, m_callerClass.getName(), "c", "()V"), + newBehaviorReferenceByConstructor(source, m_subClass.getName(), "(I)V") + )); + } + + @Test + @SuppressWarnings("unchecked") + public void subInt() { + BehaviorEntry source = newConstructor(m_subClass, "(I)V"); + assertThat(m_index.getBehaviorReferences(source), containsInAnyOrder( + newBehaviorReferenceByMethod(source, m_callerClass.getName(), "d", "()V"), + newBehaviorReferenceByConstructor(source, m_subClass.getName(), "(II)V"), + newBehaviorReferenceByConstructor(source, m_subsubClass.getName(), "(I)V") + )); + } + + @Test + @SuppressWarnings("unchecked") + public void subIntInt() { + BehaviorEntry source = newConstructor(m_subClass, "(II)V"); + assertThat(m_index.getBehaviorReferences(source), containsInAnyOrder( + newBehaviorReferenceByMethod(source, m_callerClass.getName(), "e", "()V") + )); + } + + @Test + public void subIntIntInt() { + BehaviorEntry source = newConstructor(m_subClass, "(III)V"); + assertThat(m_index.getBehaviorReferences(source), is(empty())); + } + + @Test + @SuppressWarnings("unchecked") + public void subsubInt() { + BehaviorEntry source = newConstructor(m_subsubClass, "(I)V"); + assertThat(m_index.getBehaviorReferences(source), containsInAnyOrder( + newBehaviorReferenceByMethod(source, m_callerClass.getName(), "f", "()V") + )); + } + + @Test + @SuppressWarnings("unchecked") + public void defaultConstructable() { + BehaviorEntry source = newConstructor(m_defaultClass, "()V"); + assertThat(m_index.getBehaviorReferences(source), containsInAnyOrder( + newBehaviorReferenceByMethod(source, m_callerClass.getName(), "g", "()V") + )); + } +} diff --git a/test/cuchaz/enigma/TestJarIndexInheritanceTree.java b/test/cuchaz/enigma/TestJarIndexInheritanceTree.java new file mode 100644 index 00000000..1d6e5a55 --- /dev/null +++ b/test/cuchaz/enigma/TestJarIndexInheritanceTree.java @@ -0,0 +1,228 @@ +/******************************************************************************* + * Copyright (c) 2014 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Public License v3.0 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/gpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ +package cuchaz.enigma; + +import static cuchaz.enigma.EntryFactory.*; +import static org.hamcrest.MatcherAssert.*; +import static org.hamcrest.Matchers.*; + +import java.util.Collection; +import java.util.Set; +import java.util.jar.JarFile; + +import org.junit.Test; + +import cuchaz.enigma.analysis.Access; +import cuchaz.enigma.analysis.EntryReference; +import cuchaz.enigma.analysis.JarIndex; +import cuchaz.enigma.analysis.TranslationIndex; +import cuchaz.enigma.mapping.BehaviorEntry; +import cuchaz.enigma.mapping.ClassEntry; +import cuchaz.enigma.mapping.FieldEntry; +import cuchaz.enigma.mapping.MethodEntry; + +public class TestJarIndexInheritanceTree { + + private JarIndex m_index; + + private ClassEntry m_baseClass = newClass("none/a"); + private ClassEntry m_subClassA = newClass("none/b"); + private ClassEntry m_subClassAA = newClass("none/d"); + private ClassEntry m_subClassB = newClass("none/c"); + private FieldEntry m_nameField = new FieldEntry(m_baseClass, "a"); + private FieldEntry m_numThingsField = new FieldEntry(m_subClassB, "a"); + + public TestJarIndexInheritanceTree() + throws Exception { + m_index = new JarIndex(); + m_index.indexJar(new JarFile("build/testInheritanceTree.obf.jar"), false); + } + + @Test + public void obfEntries() { + assertThat(m_index.getObfClassEntries(), containsInAnyOrder( + newClass("cuchaz/enigma/inputs/Keep"), + m_baseClass, + m_subClassA, + m_subClassAA, + m_subClassB + )); + } + + @Test + public void translationIndex() { + + TranslationIndex index = m_index.getTranslationIndex(); + + // base class + assertThat(index.getSuperclass(m_baseClass), is(nullValue())); + assertThat(index.getAncestry(m_baseClass), is(empty())); + assertThat(index.getSubclass(m_baseClass), containsInAnyOrder( + m_subClassA, + m_subClassB + )); + + // subclass a + assertThat(index.getSuperclass(m_subClassA), is(m_baseClass)); + assertThat(index.getAncestry(m_subClassA), contains(m_baseClass)); + assertThat(index.getSubclass(m_subClassA), contains(m_subClassAA)); + + // subclass aa + assertThat(index.getSuperclass(m_subClassAA), is(m_subClassA)); + assertThat(index.getAncestry(m_subClassAA), contains(m_subClassA, m_baseClass)); + assertThat(index.getSubclass(m_subClassAA), is(empty())); + + // subclass b + assertThat(index.getSuperclass(m_subClassB), is(m_baseClass)); + assertThat(index.getAncestry(m_subClassB), contains(m_baseClass)); + assertThat(index.getSubclass(m_subClassB), is(empty())); + } + + @Test + public void access() { + assertThat(m_index.getAccess(m_nameField), is(Access.Private)); + assertThat(m_index.getAccess(m_numThingsField), is(Access.Private)); + } + + @Test + public void relatedMethodImplementations() { + + Set entries; + + // getName() + entries = m_index.getRelatedMethodImplementations(newMethod(m_baseClass, "a", "()Ljava/lang/String;")); + assertThat(entries, containsInAnyOrder( + newMethod(m_baseClass, "a", "()Ljava/lang/String;"), + newMethod(m_subClassAA, "a", "()Ljava/lang/String;") + )); + entries = m_index.getRelatedMethodImplementations(newMethod(m_subClassAA, "a", "()Ljava/lang/String;")); + assertThat(entries, containsInAnyOrder( + newMethod(m_baseClass, "a", "()Ljava/lang/String;"), + newMethod(m_subClassAA, "a", "()Ljava/lang/String;") + )); + + // doBaseThings() + entries = m_index.getRelatedMethodImplementations(newMethod(m_baseClass, "a", "()V")); + assertThat(entries, containsInAnyOrder( + newMethod(m_baseClass, "a", "()V"), + newMethod(m_subClassAA, "a", "()V"), + newMethod(m_subClassB, "a", "()V") + )); + entries = m_index.getRelatedMethodImplementations(newMethod(m_subClassAA, "a", "()V")); + assertThat(entries, containsInAnyOrder( + newMethod(m_baseClass, "a", "()V"), + newMethod(m_subClassAA, "a", "()V"), + newMethod(m_subClassB, "a", "()V") + )); + entries = m_index.getRelatedMethodImplementations(newMethod(m_subClassB, "a", "()V")); + assertThat(entries, containsInAnyOrder( + newMethod(m_baseClass, "a", "()V"), + newMethod(m_subClassAA, "a", "()V"), + newMethod(m_subClassB, "a", "()V") + )); + + // doBThings + entries = m_index.getRelatedMethodImplementations(newMethod(m_subClassB, "b", "()V")); + assertThat(entries, containsInAnyOrder(newMethod(m_subClassB, "b", "()V"))); + } + + @Test + @SuppressWarnings("unchecked") + public void fieldReferences() { + Collection> references; + + // name + references = m_index.getFieldReferences(m_nameField); + assertThat(references, containsInAnyOrder( + newFieldReferenceByConstructor(m_nameField, m_baseClass.getName(), "(Ljava/lang/String;)V"), + newFieldReferenceByMethod(m_nameField, m_baseClass.getName(), "a", "()Ljava/lang/String;") + )); + + // numThings + references = m_index.getFieldReferences(m_numThingsField); + assertThat(references, containsInAnyOrder( + newFieldReferenceByConstructor(m_numThingsField, m_subClassB.getName(), "()V"), + newFieldReferenceByMethod(m_numThingsField, m_subClassB.getName(), "b", "()V") + )); + } + + @Test + @SuppressWarnings("unchecked") + public void behaviorReferences() { + + BehaviorEntry source; + Collection> references; + + // baseClass constructor + source = newConstructor(m_baseClass, "(Ljava/lang/String;)V"); + references = m_index.getBehaviorReferences(source); + assertThat(references, containsInAnyOrder( + newBehaviorReferenceByConstructor(source, m_subClassA.getName(), "(Ljava/lang/String;)V"), + newBehaviorReferenceByConstructor(source, m_subClassB.getName(), "()V") + )); + + // subClassA constructor + source = newConstructor(m_subClassA, "(Ljava/lang/String;)V"); + references = m_index.getBehaviorReferences(source); + assertThat(references, containsInAnyOrder( + newBehaviorReferenceByConstructor(source, m_subClassAA.getName(), "()V") + )); + + // baseClass.getName() + source = newMethod(m_baseClass, "a", "()Ljava/lang/String;"); + references = m_index.getBehaviorReferences(source); + assertThat(references, containsInAnyOrder( + newBehaviorReferenceByMethod(source, m_subClassAA.getName(), "a", "()Ljava/lang/String;"), + newBehaviorReferenceByMethod(source, m_subClassB.getName(), "a", "()V") + )); + + // subclassAA.getName() + source = newMethod(m_subClassAA, "a", "()Ljava/lang/String;"); + references = m_index.getBehaviorReferences(source); + assertThat(references, containsInAnyOrder( + newBehaviorReferenceByMethod(source, m_subClassAA.getName(), "a", "()V") + )); + } + + @Test + public void containsEntries() { + + // classes + assertThat(m_index.containsObfClass(m_baseClass), is(true)); + assertThat(m_index.containsObfClass(m_subClassA), is(true)); + assertThat(m_index.containsObfClass(m_subClassAA), is(true)); + assertThat(m_index.containsObfClass(m_subClassB), is(true)); + + // fields + assertThat(m_index.containsObfField(m_nameField), is(true)); + assertThat(m_index.containsObfField(m_numThingsField), is(true)); + + // methods + // getName() + assertThat(m_index.containsObfBehavior(newMethod(m_baseClass, "a", "()Ljava/lang/String;")), is(true)); + assertThat(m_index.containsObfBehavior(newMethod(m_subClassA, "a", "()Ljava/lang/String;")), is(false)); + assertThat(m_index.containsObfBehavior(newMethod(m_subClassAA, "a", "()Ljava/lang/String;")), is(true)); + assertThat(m_index.containsObfBehavior(newMethod(m_subClassB, "a", "()Ljava/lang/String;")), is(false)); + + // doBaseThings() + assertThat(m_index.containsObfBehavior(newMethod(m_baseClass, "a", "()V")), is(true)); + assertThat(m_index.containsObfBehavior(newMethod(m_subClassA, "a", "()V")), is(false)); + assertThat(m_index.containsObfBehavior(newMethod(m_subClassAA, "a", "()V")), is(true)); + assertThat(m_index.containsObfBehavior(newMethod(m_subClassB, "a", "()V")), is(true)); + + // doBThings() + assertThat(m_index.containsObfBehavior(newMethod(m_baseClass, "b", "()V")), is(false)); + assertThat(m_index.containsObfBehavior(newMethod(m_subClassA, "b", "()V")), is(false)); + assertThat(m_index.containsObfBehavior(newMethod(m_subClassAA, "b", "()V")), is(false)); + assertThat(m_index.containsObfBehavior(newMethod(m_subClassB, "b", "()V")), is(true)); + + } +} diff --git a/test/cuchaz/enigma/TestJarIndexLoneClass.java b/test/cuchaz/enigma/TestJarIndexLoneClass.java new file mode 100644 index 00000000..c6a9e550 --- /dev/null +++ b/test/cuchaz/enigma/TestJarIndexLoneClass.java @@ -0,0 +1,165 @@ +/******************************************************************************* + * Copyright (c) 2014 Jeff Martin. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Public License v3.0 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/gpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ +package cuchaz.enigma; + +import static cuchaz.enigma.EntryFactory.*; +import static org.hamcrest.MatcherAssert.*; +import static org.hamcrest.Matchers.*; + +import java.util.Collection; +import java.util.Set; +import java.util.jar.JarFile; + +import org.junit.Test; + +import cuchaz.enigma.analysis.Access; +import cuchaz.enigma.analysis.ClassImplementationsTreeNode; +import cuchaz.enigma.analysis.ClassInheritanceTreeNode; +import cuchaz.enigma.analysis.EntryReference; +import cuchaz.enigma.analysis.JarIndex; +import cuchaz.enigma.analysis.MethodImplementationsTreeNode; +import cuchaz.enigma.analysis.MethodInheritanceTreeNode; +import cuchaz.enigma.mapping.BehaviorEntry; +import cuchaz.enigma.mapping.ClassEntry; +import cuchaz.enigma.mapping.FieldEntry; +import cuchaz.enigma.mapping.MethodEntry; +import cuchaz.enigma.mapping.Translator; + +public class TestJarIndexLoneClass { + + private JarIndex m_index; + + public TestJarIndexLoneClass() + throws Exception { + m_index = new JarIndex(); + m_index.indexJar(new JarFile("build/testLoneClass.obf.jar"), false); + } + + @Test + public void obfEntries() { + assertThat(m_index.getObfClassEntries(), containsInAnyOrder( + newClass("cuchaz/enigma/inputs/Keep"), + newClass("none/a") + )); + } + + @Test + public void translationIndex() { + assertThat(m_index.getTranslationIndex().getSuperclass(new ClassEntry("none/a")), is(nullValue())); + assertThat(m_index.getTranslationIndex().getSuperclass(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(nullValue())); + assertThat(m_index.getTranslationIndex().getAncestry(new ClassEntry("none/a")), is(empty())); + assertThat(m_index.getTranslationIndex().getAncestry(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(empty())); + assertThat(m_index.getTranslationIndex().getSubclass(new ClassEntry("none/a")), is(empty())); + assertThat(m_index.getTranslationIndex().getSubclass(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(empty())); + } + + @Test + public void access() { + assertThat(m_index.getAccess(newField("none/a", "a")), is(Access.Private)); + assertThat(m_index.getAccess(newMethod("none/a", "a", "()Ljava/lang/String;")), is(Access.Public)); + assertThat(m_index.getAccess(newField("none/a", "b")), is(nullValue())); + } + + @Test + public void classInheritance() { + ClassInheritanceTreeNode node = m_index.getClassInheritance(new Translator(), newClass("none/a")); + assertThat(node, is(not(nullValue()))); + assertThat(node.getObfClassName(), is("none/a")); + assertThat(node.getChildCount(), is(0)); + } + + @Test + public void methodInheritance() { + MethodEntry source = newMethod("none/a", "a", "()Ljava/lang/String;"); + MethodInheritanceTreeNode node = m_index.getMethodInheritance(new Translator(), source); + assertThat(node, is(not(nullValue()))); + assertThat(node.getMethodEntry(), is(source)); + assertThat(node.getChildCount(), is(0)); + } + + @Test + public void classImplementations() { + ClassImplementationsTreeNode node = m_index.getClassImplementations(new Translator(), newClass("none/a")); + assertThat(node, is(nullValue())); + } + + @Test + public void methodImplementations() { + MethodEntry source = newMethod("none/a", "a", "()Ljava/lang/String;"); + MethodImplementationsTreeNode node = m_index.getMethodImplementations(new Translator(), source); + assertThat(node, is(nullValue())); + } + + @Test + public void relatedMethodImplementations() { + Set entries = m_index.getRelatedMethodImplementations(newMethod("none/a", "a", "()Ljava/lang/String;")); + assertThat(entries, containsInAnyOrder( + newMethod("none/a", "a", "()Ljava/lang/String;") + )); + } + + @Test + @SuppressWarnings("unchecked") + public void fieldReferences() { + FieldEntry source = newField("none/a", "a"); + Collection> references = m_index.getFieldReferences(source); + assertThat(references, containsInAnyOrder( + newFieldReferenceByConstructor(source, "none/a", "(Ljava/lang/String;)V"), + newFieldReferenceByMethod(source, "none/a", "a", "()Ljava/lang/String;") + )); + } + + @Test + public void behaviorReferences() { + assertThat(m_index.getBehaviorReferences(newMethod("none/a", "a", "()Ljava/lang/String;")), is(empty())); + } + + @Test + public void innerClasses() { + assertThat(m_index.getInnerClasses("none/a"), is(empty())); + } + + @Test + public void outerClass() { + assertThat(m_index.getOuterClass("a"), is(nullValue())); + } + + @Test + public void isAnonymousClass() { + assertThat(m_index.isAnonymousClass("none/a"), is(false)); + } + + @Test + public void interfaces() { + assertThat(m_index.getInterfaces("none/a"), is(empty())); + } + + @Test + public void implementingClasses() { + assertThat(m_index.getImplementingClasses("none/a"), is(empty())); + } + + @Test + public void isInterface() { + assertThat(m_index.isInterface("none/a"), is(false)); + } + + @Test + public void contains() { + assertThat(m_index.containsObfClass(newClass("none/a")), is(true)); + assertThat(m_index.containsObfClass(newClass("none/b")), is(false)); + assertThat(m_index.containsObfField(newField("none/a", "a")), is(true)); + assertThat(m_index.containsObfField(newField("none/a", "b")), is(false)); + assertThat(m_index.containsObfBehavior(newMethod("none/a", "a", "()Ljava/lang/String;")), is(true)); + assertThat(m_index.containsObfBehavior(newMethod("none/a", "b", "()Ljava/lang/String;")), is(false)); + } +} diff --git a/test/cuchaz/enigma/TestSignature.java b/test/cuchaz/enigma/TestSignature.java new file mode 100644 index 00000000..183a4fd4 --- /dev/null +++ b/test/cuchaz/enigma/TestSignature.java @@ -0,0 +1,266 @@ +package cuchaz.enigma; + +import static org.hamcrest.MatcherAssert.*; +import static org.hamcrest.Matchers.*; + +import org.junit.Test; + +import cuchaz.enigma.mapping.ClassNameReplacer; +import cuchaz.enigma.mapping.Signature; +import cuchaz.enigma.mapping.Type; + + +public class TestSignature { + + @Test + public void easiest() { + final Signature sig = new Signature("()V"); + assertThat(sig.getArgumentTypes(), is(empty())); + assertThat(sig.getReturnType(), is(new Type("V"))); + } + + @Test + public void primitives() { + { + final Signature sig = new Signature("(I)V"); + assertThat(sig.getArgumentTypes(), contains( + new Type("I") + )); + assertThat(sig.getReturnType(), is(new Type("V"))); + } + { + final Signature sig = new Signature("(I)I"); + assertThat(sig.getArgumentTypes(), contains( + new Type("I") + )); + assertThat(sig.getReturnType(), is(new Type("I"))); + } + { + final Signature sig = new Signature("(IBCJ)Z"); + assertThat(sig.getArgumentTypes(), contains( + new Type("I"), + new Type("B"), + new Type("C"), + new Type("J") + )); + assertThat(sig.getReturnType(), is(new Type("Z"))); + } + } + + @Test + public void classes() { + { + final Signature sig = new Signature("([LFoo;)V"); + assertThat(sig.getArgumentTypes().size(), is(1)); + assertThat(sig.getArgumentTypes().get(0), is(new Type("[LFoo;"))); + assertThat(sig.getReturnType(), is(new Type("V"))); + } + { + final Signature sig = new Signature("(LFoo;)LBar;"); + assertThat(sig.getArgumentTypes(), contains( + new Type("LFoo;") + )); + assertThat(sig.getReturnType(), is(new Type("LBar;"))); + } + { + final Signature sig = new Signature("(LFoo;LMoo;LZoo;)LBar;"); + assertThat(sig.getArgumentTypes(), contains( + new Type("LFoo;"), + new Type("LMoo;"), + new Type("LZoo;") + )); + assertThat(sig.getReturnType(), is(new Type("LBar;"))); + } + { + final Signature sig = new Signature("(LFoo;LMoo;)LBar;"); + assertThat(sig.getArgumentTypes(), contains( + new Type("LFoo;"), + new Type("LMoo;") + )); + assertThat(sig.getReturnType(), is(new Type("LBar;"))); + } + } + + @Test + public void arrays() { + { + final Signature sig = new Signature("([I)V"); + assertThat(sig.getArgumentTypes(), contains( + new Type("[I") + )); + assertThat(sig.getReturnType(), is(new Type("V"))); + } + { + final Signature sig = new Signature("([I)[J"); + assertThat(sig.getArgumentTypes(), contains( + new Type("[I") + )); + assertThat(sig.getReturnType(), is(new Type("[J"))); + } + { + final Signature sig = new Signature("([I[Z[F)[D"); + assertThat(sig.getArgumentTypes(), contains( + new Type("[I"), + new Type("[Z"), + new Type("[F") + )); + assertThat(sig.getReturnType(), is(new Type("[D"))); + } + } + + @Test + public void mixed() { + { + final Signature sig = new Signature("(I[JLFoo;)Z"); + assertThat(sig.getArgumentTypes(), contains( + new Type("I"), + new Type("[J"), + new Type("LFoo;") + )); + assertThat(sig.getReturnType(), is(new Type("Z"))); + } + { + final Signature sig = new Signature("(III)[LFoo;"); + assertThat(sig.getArgumentTypes(), contains( + new Type("I"), + new Type("I"), + new Type("I") + )); + assertThat(sig.getReturnType(), is(new Type("[LFoo;"))); + } + } + + @Test + public void replaceClasses() { + { + final Signature oldSig = new Signature("()V"); + final Signature sig = new Signature(oldSig, new ClassNameReplacer() { + @Override + public String replace(String val) { + return null; + } + }); + assertThat(sig.getArgumentTypes(), is(empty())); + assertThat(sig.getReturnType(), is(new Type("V"))); + } + { + final Signature oldSig = new Signature("(IJLFoo;)V"); + final Signature sig = new Signature(oldSig, new ClassNameReplacer() { + @Override + public String replace(String val) { + return null; + } + }); + assertThat(sig.getArgumentTypes(), contains( + new Type("I"), + new Type("J"), + new Type("LFoo;") + )); + assertThat(sig.getReturnType(), is(new Type("V"))); + } + { + final Signature oldSig = new Signature("(LFoo;LBar;)LMoo;"); + final Signature sig = new Signature(oldSig, new ClassNameReplacer() { + @Override + public String replace(String val) { + if (val.equals("Foo")) { + return "Bar"; + } + return null; + } + }); + assertThat(sig.getArgumentTypes(), contains( + new Type("LBar;"), + new Type("LBar;") + )); + assertThat(sig.getReturnType(), is(new Type("LMoo;"))); + } + { + final Signature oldSig = new Signature("(LFoo;LBar;)LMoo;"); + final Signature sig = new Signature(oldSig, new ClassNameReplacer() { + @Override + public String replace(String val) { + if (val.equals("Moo")) { + return "Cow"; + } + return null; + } + }); + assertThat(sig.getArgumentTypes(), contains( + new Type("LFoo;"), + new Type("LBar;") + )); + assertThat(sig.getReturnType(), is(new Type("LCow;"))); + } + } + + @Test + public void replaceArrayClasses() { + { + final Signature oldSig = new Signature("([LFoo;)[[[LBar;"); + final Signature sig = new Signature(oldSig, new ClassNameReplacer() { + @Override + public String replace(String val) { + if (val.equals("Foo")) { + return "Food"; + } else if (val.equals("Bar")) { + return "Beer"; + } + return null; + } + }); + assertThat(sig.getArgumentTypes(), contains( + new Type("[LFood;") + )); + assertThat(sig.getReturnType(), is(new Type("[[[LBeer;"))); + } + } + + @Test + public void equals() { + + // base + assertThat(new Signature("()V"), is(new Signature("()V"))); + + // arguments + assertThat(new Signature("(I)V"), is(new Signature("(I)V"))); + assertThat(new Signature("(ZIZ)V"), is(new Signature("(ZIZ)V"))); + assertThat(new Signature("(LFoo;)V"), is(new Signature("(LFoo;)V"))); + assertThat(new Signature("(LFoo;LBar;)V"), is(new Signature("(LFoo;LBar;)V"))); + assertThat(new Signature("([I)V"), is(new Signature("([I)V"))); + assertThat(new Signature("([[D[[[J)V"), is(new Signature("([[D[[[J)V"))); + + assertThat(new Signature("()V"), is(not(new Signature("(I)V")))); + assertThat(new Signature("(I)V"), is(not(new Signature("()V")))); + assertThat(new Signature("(IJ)V"), is(not(new Signature("(JI)V")))); + assertThat(new Signature("([[Z)V"), is(not(new Signature("([[LFoo;)V")))); + assertThat(new Signature("(LFoo;LBar;)V"), is(not(new Signature("(LFoo;LCow;)V")))); + assertThat(new Signature("([LFoo;LBar;)V"), is(not(new Signature("(LFoo;LCow;)V")))); + + // return type + assertThat(new Signature("()I"), is(new Signature("()I"))); + assertThat(new Signature("()Z"), is(new Signature("()Z"))); + assertThat(new Signature("()[D"), is(new Signature("()[D"))); + assertThat(new Signature("()[[[Z"), is(new Signature("()[[[Z"))); + assertThat(new Signature("()LFoo;"), is(new Signature("()LFoo;"))); + assertThat(new Signature("()[LFoo;"), is(new Signature("()[LFoo;"))); + + assertThat(new Signature("()I"), is(not(new Signature("()Z")))); + assertThat(new Signature("()Z"), is(not(new Signature("()I")))); + assertThat(new Signature("()[D"), is(not(new Signature("()[J")))); + assertThat(new Signature("()[[[Z"), is(not(new Signature("()[[Z")))); + assertThat(new Signature("()LFoo;"), is(not(new Signature("()LBar;")))); + assertThat(new Signature("()[LFoo;"), is(not(new Signature("()[LBar;")))); + } + + @Test + public void testToString() { + assertThat(new Signature("()V").toString(), is("()V")); + assertThat(new Signature("(I)V").toString(), is("(I)V")); + assertThat(new Signature("(ZIZ)V").toString(), is("(ZIZ)V")); + assertThat(new Signature("(LFoo;)V").toString(), is("(LFoo;)V")); + assertThat(new Signature("(LFoo;LBar;)V").toString(), is("(LFoo;LBar;)V")); + assertThat(new Signature("([I)V").toString(), is("([I)V")); + assertThat(new Signature("([[D[[[J)V").toString(), is("([[D[[[J)V")); + } +} diff --git a/test/cuchaz/enigma/TestSourceIndex.java b/test/cuchaz/enigma/TestSourceIndex.java new file mode 100644 index 00000000..357acb62 --- /dev/null +++ b/test/cuchaz/enigma/TestSourceIndex.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2014 Jeff Martin. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Public License v3.0 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/gpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ +package cuchaz.enigma; + +import java.util.Set; +import java.util.jar.JarFile; + +import org.junit.Test; + +import com.google.common.collect.Sets; +import com.strobel.decompiler.languages.java.ast.CompilationUnit; + +import cuchaz.enigma.mapping.ClassEntry; + +public class TestSourceIndex { + + // TEMP + //@Test + public void indexEverything() + throws Exception { + Deobfuscator deobfuscator = new Deobfuscator(new JarFile("input/1.8.jar")); + + // get all classes that aren't inner classes + Set classEntries = Sets.newHashSet(); + for (ClassEntry obfClassEntry : deobfuscator.getJarIndex().getObfClassEntries()) { + if (!obfClassEntry.isInnerClass()) { + classEntries.add(obfClassEntry); + } + } + + for (ClassEntry obfClassEntry : classEntries) { + try { + CompilationUnit tree = deobfuscator.getSourceTree(obfClassEntry.getName()); + String source = deobfuscator.getSource(tree); + deobfuscator.getSourceIndex(tree, source); + } catch (Throwable t) { + throw new Error("Unable to index " + obfClassEntry, t); + } + } + } +} diff --git a/test/cuchaz/enigma/TestTokensConstructors.java b/test/cuchaz/enigma/TestTokensConstructors.java new file mode 100644 index 00000000..6758d2a7 --- /dev/null +++ b/test/cuchaz/enigma/TestTokensConstructors.java @@ -0,0 +1,136 @@ +/******************************************************************************* + * Copyright (c) 2014 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Public License v3.0 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/gpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ +package cuchaz.enigma; + +import static cuchaz.enigma.EntryFactory.*; +import static org.hamcrest.MatcherAssert.*; +import static org.hamcrest.Matchers.*; + +import java.util.jar.JarFile; + +import org.junit.Test; + +import cuchaz.enigma.mapping.BehaviorEntry; + +public class TestTokensConstructors extends TokenChecker { + + public TestTokensConstructors() + throws Exception { + super(new JarFile("build/testConstructors.obf.jar")); + } + + @Test + public void baseDeclarations() { + assertThat(getDeclarationToken(newConstructor("none/a", "()V")), is("a")); + assertThat(getDeclarationToken(newConstructor("none/a", "(I)V")), is("a")); + } + + @Test + public void subDeclarations() { + assertThat(getDeclarationToken(newConstructor("none/d", "()V")), is("d")); + assertThat(getDeclarationToken(newConstructor("none/d", "(I)V")), is("d")); + assertThat(getDeclarationToken(newConstructor("none/d", "(II)V")), is("d")); + assertThat(getDeclarationToken(newConstructor("none/d", "(III)V")), is("d")); + } + + @Test + public void subsubDeclarations() { + assertThat(getDeclarationToken(newConstructor("none/e", "(I)V")), is("e")); + } + + @Test + public void defaultDeclarations() { + assertThat(getDeclarationToken(newConstructor("none/c", "()V")), nullValue()); + } + + @Test + public void baseDefaultReferences() { + BehaviorEntry source = newConstructor("none/a", "()V"); + assertThat( + getReferenceTokens(newBehaviorReferenceByMethod(source, "none/b", "a", "()V")), + containsInAnyOrder("a") + ); + assertThat( + getReferenceTokens(newBehaviorReferenceByConstructor(source, "none/d", "()V")), + is(empty()) // implicit call, not decompiled to token + ); + assertThat( + getReferenceTokens(newBehaviorReferenceByConstructor(source, "none/d", "(III)V")), + is(empty()) // implicit call, not decompiled to token + ); + } + + @Test + public void baseIntReferences() { + BehaviorEntry source = newConstructor("none/a", "(I)V"); + assertThat( + getReferenceTokens(newBehaviorReferenceByMethod(source, "none/b", "b", "()V")), + containsInAnyOrder("a") + ); + } + + @Test + public void subDefaultReferences() { + BehaviorEntry source = newConstructor("none/d", "()V"); + assertThat( + getReferenceTokens(newBehaviorReferenceByMethod(source, "none/b", "c", "()V")), + containsInAnyOrder("d") + ); + assertThat( + getReferenceTokens(newBehaviorReferenceByConstructor(source, "none/d", "(I)V")), + containsInAnyOrder("this") + ); + } + + @Test + public void subIntReferences() { + BehaviorEntry source = newConstructor("none/d", "(I)V"); + assertThat(getReferenceTokens( + newBehaviorReferenceByMethod(source, "none/b", "d", "()V")), + containsInAnyOrder("d") + ); + assertThat(getReferenceTokens( + newBehaviorReferenceByConstructor(source, "none/d", "(II)V")), + containsInAnyOrder("this") + ); + assertThat(getReferenceTokens( + newBehaviorReferenceByConstructor(source, "none/e", "(I)V")), + containsInAnyOrder("super") + ); + } + + @Test + public void subIntIntReferences() { + BehaviorEntry source = newConstructor("none/d", "(II)V"); + assertThat( + getReferenceTokens(newBehaviorReferenceByMethod(source, "none/b", "e", "()V")), + containsInAnyOrder("d") + ); + } + + @Test + public void subsubIntReferences() { + BehaviorEntry source = newConstructor("none/e", "(I)V"); + assertThat( + getReferenceTokens(newBehaviorReferenceByMethod(source, "none/b", "f", "()V")), + containsInAnyOrder("e") + ); + } + + @Test + public void defaultConstructableReferences() { + BehaviorEntry source = newConstructor("none/c", "()V"); + assertThat( + getReferenceTokens(newBehaviorReferenceByMethod(source, "none/b", "g", "()V")), + containsInAnyOrder("c") + ); + } +} diff --git a/test/cuchaz/enigma/TestTranslator.java b/test/cuchaz/enigma/TestTranslator.java new file mode 100644 index 00000000..290f6f04 --- /dev/null +++ b/test/cuchaz/enigma/TestTranslator.java @@ -0,0 +1,39 @@ +package cuchaz.enigma; + +import static cuchaz.enigma.EntryFactory.*; +import static org.hamcrest.MatcherAssert.*; +import static org.hamcrest.Matchers.*; + +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.jar.JarFile; + +import org.junit.Test; + +import cuchaz.enigma.mapping.Mappings; +import cuchaz.enigma.mapping.MappingsReader; +import cuchaz.enigma.mapping.TranslationDirection; +import cuchaz.enigma.mapping.Translator; + + +public class TestTranslator { + + private Deobfuscator m_deobfuscator; + private Mappings m_mappings; + + public TestTranslator() + throws Exception { + m_deobfuscator = new Deobfuscator(new JarFile("build/testTranslation.obf.jar")); + try (InputStream in = getClass().getResourceAsStream("/cuchaz/enigma/resources/translation.mappings")) { + m_mappings = new MappingsReader().read(new InputStreamReader(in)); + m_deobfuscator.setMappings(m_mappings); + } + } + + @Test + public void deobfuscatingTranslations() + throws Exception { + Translator translator = m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating); + assertThat(translator.translateEntry(newClass("none/a")), is(newClass("deobf/A"))); + } +} diff --git a/test/cuchaz/enigma/TestType.java b/test/cuchaz/enigma/TestType.java new file mode 100644 index 00000000..7c3cebe2 --- /dev/null +++ b/test/cuchaz/enigma/TestType.java @@ -0,0 +1,229 @@ +package cuchaz.enigma; + +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.*; +import static org.hamcrest.Matchers.*; + +import cuchaz.enigma.mapping.Type; + +import static cuchaz.enigma.EntryFactory.*; + + +public class TestType { + + @Test + public void isVoid() { + assertThat(new Type("V").isVoid(), is(true)); + assertThat(new Type("Z").isVoid(), is(false)); + assertThat(new Type("B").isVoid(), is(false)); + assertThat(new Type("C").isVoid(), is(false)); + assertThat(new Type("I").isVoid(), is(false)); + assertThat(new Type("J").isVoid(), is(false)); + assertThat(new Type("F").isVoid(), is(false)); + assertThat(new Type("D").isVoid(), is(false)); + assertThat(new Type("LFoo;").isVoid(), is(false)); + assertThat(new Type("[I").isVoid(), is(false)); + } + + @Test + public void isPrimitive() { + assertThat(new Type("V").isPrimitive(), is(false)); + assertThat(new Type("Z").isPrimitive(), is(true)); + assertThat(new Type("B").isPrimitive(), is(true)); + assertThat(new Type("C").isPrimitive(), is(true)); + assertThat(new Type("I").isPrimitive(), is(true)); + assertThat(new Type("J").isPrimitive(), is(true)); + assertThat(new Type("F").isPrimitive(), is(true)); + assertThat(new Type("D").isPrimitive(), is(true)); + assertThat(new Type("LFoo;").isPrimitive(), is(false)); + assertThat(new Type("[I").isPrimitive(), is(false)); + } + + @Test + public void getPrimitive() { + assertThat(new Type("Z").getPrimitive(), is(Type.Primitive.Boolean)); + assertThat(new Type("B").getPrimitive(), is(Type.Primitive.Byte)); + assertThat(new Type("C").getPrimitive(), is(Type.Primitive.Character)); + assertThat(new Type("I").getPrimitive(), is(Type.Primitive.Integer)); + assertThat(new Type("J").getPrimitive(), is(Type.Primitive.Long)); + assertThat(new Type("F").getPrimitive(), is(Type.Primitive.Float)); + assertThat(new Type("D").getPrimitive(), is(Type.Primitive.Double)); + } + + @Test + public void isClass() { + assertThat(new Type("V").isClass(), is(false)); + assertThat(new Type("Z").isClass(), is(false)); + assertThat(new Type("B").isClass(), is(false)); + assertThat(new Type("C").isClass(), is(false)); + assertThat(new Type("I").isClass(), is(false)); + assertThat(new Type("J").isClass(), is(false)); + assertThat(new Type("F").isClass(), is(false)); + assertThat(new Type("D").isClass(), is(false)); + assertThat(new Type("LFoo;").isClass(), is(true)); + assertThat(new Type("[I").isClass(), is(false)); + } + + @Test + public void getClassEntry() { + assertThat(new Type("LFoo;").getClassEntry(), is(newClass("Foo"))); + assertThat(new Type("LFoo;").getClassEntry(), is(newClass("Foo"))); + } + + @Test + public void getArrayClassEntry() { + assertThat(new Type("[LFoo;").getClassEntry(), is(newClass("Foo"))); + assertThat(new Type("[[[LFoo;").getClassEntry(), is(newClass("Foo"))); + } + + @Test + public void isArray() { + assertThat(new Type("V").isArray(), is(false)); + assertThat(new Type("Z").isArray(), is(false)); + assertThat(new Type("B").isArray(), is(false)); + assertThat(new Type("C").isArray(), is(false)); + assertThat(new Type("I").isArray(), is(false)); + assertThat(new Type("J").isArray(), is(false)); + assertThat(new Type("F").isArray(), is(false)); + assertThat(new Type("D").isArray(), is(false)); + assertThat(new Type("LFoo;").isArray(), is(false)); + assertThat(new Type("[I").isArray(), is(true)); + } + + @Test + public void getArrayDimension() { + assertThat(new Type("[I").getArrayDimension(), is(1)); + assertThat(new Type("[[I").getArrayDimension(), is(2)); + assertThat(new Type("[[[I").getArrayDimension(), is(3)); + } + + @Test + public void getArrayType() { + assertThat(new Type("[I").getArrayType(), is(new Type("I"))); + assertThat(new Type("[[I").getArrayType(), is(new Type("I"))); + assertThat(new Type("[[[I").getArrayType(), is(new Type("I"))); + assertThat(new Type("[Ljava/lang/String;").getArrayType(), is(new Type("Ljava/lang/String;"))); + } + + @Test + public void hasClass() { + assertThat(new Type("LFoo;").hasClass(), is(true)); + assertThat(new Type("LCow;").hasClass(), is(true)); + assertThat(new Type("[LBar;").hasClass(), is(true)); + assertThat(new Type("[[[LCat;").hasClass(), is(true)); + + assertThat(new Type("V").hasClass(), is(false)); + assertThat(new Type("[I").hasClass(), is(false)); + assertThat(new Type("[[[I").hasClass(), is(false)); + assertThat(new Type("Z").hasClass(), is(false)); + } + + @Test + public void parseVoid() { + final String answer = "V"; + assertThat(Type.parseFirst("V"), is(answer)); + assertThat(Type.parseFirst("VVV"), is(answer)); + assertThat(Type.parseFirst("VIJ"), is(answer)); + assertThat(Type.parseFirst("V[I"), is(answer)); + assertThat(Type.parseFirst("VLFoo;"), is(answer)); + assertThat(Type.parseFirst("V[LFoo;"), is(answer)); + } + + @Test + public void parsePrimitive() { + final String answer = "I"; + assertThat(Type.parseFirst("I"), is(answer)); + assertThat(Type.parseFirst("III"), is(answer)); + assertThat(Type.parseFirst("IJZ"), is(answer)); + assertThat(Type.parseFirst("I[I"), is(answer)); + assertThat(Type.parseFirst("ILFoo;"), is(answer)); + assertThat(Type.parseFirst("I[LFoo;"), is(answer)); + } + + @Test + public void parseClass() { + { + final String answer = "LFoo;"; + assertThat(Type.parseFirst("LFoo;"), is(answer)); + assertThat(Type.parseFirst("LFoo;I"), is(answer)); + assertThat(Type.parseFirst("LFoo;JZ"), is(answer)); + assertThat(Type.parseFirst("LFoo;[I"), is(answer)); + assertThat(Type.parseFirst("LFoo;LFoo;"), is(answer)); + assertThat(Type.parseFirst("LFoo;[LFoo;"), is(answer)); + } + { + final String answer = "LFoo;"; + assertThat(Type.parseFirst("LFoo;"), is(answer)); + assertThat(Type.parseFirst("LFoo;I"), is(answer)); + assertThat(Type.parseFirst("LFoo;JZ"), is(answer)); + assertThat(Type.parseFirst("LFoo;[I"), is(answer)); + assertThat(Type.parseFirst("LFoo;LFoo;"), is(answer)); + assertThat(Type.parseFirst("LFoo;[LFoo;"), is(answer)); + } + { + final String answer = "LFoo;"; + assertThat(Type.parseFirst("LFoo;"), is(answer)); + assertThat(Type.parseFirst("LFoo;I"), is(answer)); + assertThat(Type.parseFirst("LFoo;JZ"), is(answer)); + assertThat(Type.parseFirst("LFoo;[I"), is(answer)); + assertThat(Type.parseFirst("LFoo;LFoo;"), is(answer)); + assertThat(Type.parseFirst("LFoo;[LFoo;"), is(answer)); + } + } + + @Test + public void parseArray() { + { + final String answer = "[I"; + assertThat(Type.parseFirst("[I"), is(answer)); + assertThat(Type.parseFirst("[III"), is(answer)); + assertThat(Type.parseFirst("[IJZ"), is(answer)); + assertThat(Type.parseFirst("[I[I"), is(answer)); + assertThat(Type.parseFirst("[ILFoo;"), is(answer)); + } + { + final String answer = "[[I"; + assertThat(Type.parseFirst("[[I"), is(answer)); + assertThat(Type.parseFirst("[[III"), is(answer)); + assertThat(Type.parseFirst("[[IJZ"), is(answer)); + assertThat(Type.parseFirst("[[I[I"), is(answer)); + assertThat(Type.parseFirst("[[ILFoo;"), is(answer)); + } + { + final String answer = "[LFoo;"; + assertThat(Type.parseFirst("[LFoo;"), is(answer)); + assertThat(Type.parseFirst("[LFoo;II"), is(answer)); + assertThat(Type.parseFirst("[LFoo;JZ"), is(answer)); + assertThat(Type.parseFirst("[LFoo;[I"), is(answer)); + assertThat(Type.parseFirst("[LFoo;LFoo;"), is(answer)); + } + } + + @Test + public void equals() { + assertThat(new Type("V"), is(new Type("V"))); + assertThat(new Type("Z"), is(new Type("Z"))); + assertThat(new Type("B"), is(new Type("B"))); + assertThat(new Type("C"), is(new Type("C"))); + assertThat(new Type("I"), is(new Type("I"))); + assertThat(new Type("J"), is(new Type("J"))); + assertThat(new Type("F"), is(new Type("F"))); + assertThat(new Type("D"), is(new Type("D"))); + assertThat(new Type("LFoo;"), is(new Type("LFoo;"))); + assertThat(new Type("[I"), is(new Type("[I"))); + assertThat(new Type("[[[I"), is(new Type("[[[I"))); + assertThat(new Type("[LFoo;"), is(new Type("[LFoo;"))); + assertThat(new Type("LFoo;"), is(new Type("LFoo;"))); + + assertThat(new Type("V"), is(not(new Type("I")))); + assertThat(new Type("I"), is(not(new Type("J")))); + assertThat(new Type("I"), is(not(new Type("LBar;")))); + assertThat(new Type("I"), is(not(new Type("[I")))); + assertThat(new Type("LFoo;"), is(not(new Type("LBar;")))); + assertThat(new Type("LFoo;"), is(not(new Type("LFoo;")))); + assertThat(new Type("[I"), is(not(new Type("[Z")))); + assertThat(new Type("[[[I"), is(not(new Type("[I")))); + assertThat(new Type("[LFoo;"), is(not(new Type("[LBar;")))); + } +} diff --git a/test/cuchaz/enigma/TokenChecker.java b/test/cuchaz/enigma/TokenChecker.java new file mode 100644 index 00000000..a72c2fc8 --- /dev/null +++ b/test/cuchaz/enigma/TokenChecker.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2014 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Public License v3.0 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/gpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ +package cuchaz.enigma; + +import java.io.IOException; +import java.util.Collection; +import java.util.List; +import java.util.jar.JarFile; + +import com.google.common.collect.Lists; +import com.strobel.decompiler.languages.java.ast.CompilationUnit; + +import cuchaz.enigma.analysis.EntryReference; +import cuchaz.enigma.analysis.SourceIndex; +import cuchaz.enigma.analysis.Token; +import cuchaz.enigma.mapping.Entry; + +public class TokenChecker { + + private Deobfuscator m_deobfuscator; + + protected TokenChecker(JarFile jarFile) + throws IOException { + m_deobfuscator = new Deobfuscator(jarFile); + } + + protected String getDeclarationToken(Entry entry) { + // decompile the class + CompilationUnit tree = m_deobfuscator.getSourceTree(entry.getClassName()); + // DEBUG + // tree.acceptVisitor( new TreeDumpVisitor( new File( "tree." + entry.getClassName().replace( '/', '.' ) + ".txt" ) ), null ); + String source = m_deobfuscator.getSource(tree); + SourceIndex index = m_deobfuscator.getSourceIndex(tree, source); + + // get the token value + Token token = index.getDeclarationToken(entry); + if (token == null) { + return null; + } + return source.substring(token.start, token.end); + } + + @SuppressWarnings("unchecked") + protected Collection getReferenceTokens(EntryReference reference) { + // decompile the class + CompilationUnit tree = m_deobfuscator.getSourceTree(reference.context.getClassName()); + String source = m_deobfuscator.getSource(tree); + SourceIndex index = m_deobfuscator.getSourceIndex(tree, source); + + // get the token values + List values = Lists.newArrayList(); + for (Token token : index.getReferenceTokens((EntryReference)reference)) { + values.add(source.substring(token.start, token.end)); + } + return values; + } +} diff --git a/test/cuchaz/enigma/inputs/Keep.java b/test/cuchaz/enigma/inputs/Keep.java new file mode 100644 index 00000000..390e82fb --- /dev/null +++ b/test/cuchaz/enigma/inputs/Keep.java @@ -0,0 +1,7 @@ +package cuchaz.enigma.inputs; + +public class Keep { + public static void main(String[] args) { + System.out.println("Keep me!"); + } +} diff --git a/test/cuchaz/enigma/inputs/constructors/BaseClass.java b/test/cuchaz/enigma/inputs/constructors/BaseClass.java new file mode 100644 index 00000000..93453086 --- /dev/null +++ b/test/cuchaz/enigma/inputs/constructors/BaseClass.java @@ -0,0 +1,15 @@ +package cuchaz.enigma.inputs.constructors; + +// none/a +public class BaseClass { + + // ()V + public BaseClass() { + System.out.println("Default constructor"); + } + + // (I)V + public BaseClass(int i) { + System.out.println("Int constructor " + i); + } +} diff --git a/test/cuchaz/enigma/inputs/constructors/Caller.java b/test/cuchaz/enigma/inputs/constructors/Caller.java new file mode 100644 index 00000000..57278751 --- /dev/null +++ b/test/cuchaz/enigma/inputs/constructors/Caller.java @@ -0,0 +1,47 @@ +package cuchaz.enigma.inputs.constructors; + +// none/b +public class Caller { + + // a()V + public void callBaseDefault() { + // none/a.()V + System.out.println(new BaseClass()); + } + + // b()V + public void callBaseInt() { + // none/a.(I)V + System.out.println(new BaseClass(5)); + } + + // c()V + public void callSubDefault() { + // none/d.()V + System.out.println(new SubClass()); + } + + // d()V + public void callSubInt() { + // none/d.(I)V + System.out.println(new SubClass(6)); + } + + // e()V + public void callSubIntInt() { + // none/d.(II)V + System.out.println(new SubClass(4, 2)); + } + + // f()V + public void callSubSubInt() { + // none/e.(I)V + System.out.println(new SubSubClass(3)); + } + + // g()V + public void callDefaultConstructable() { + // none/c.()V + System.out.println(new DefaultConstructable()); + } +} diff --git a/test/cuchaz/enigma/inputs/constructors/DefaultConstructable.java b/test/cuchaz/enigma/inputs/constructors/DefaultConstructable.java new file mode 100644 index 00000000..26a3ddbb --- /dev/null +++ b/test/cuchaz/enigma/inputs/constructors/DefaultConstructable.java @@ -0,0 +1,5 @@ +package cuchaz.enigma.inputs.constructors; + +public class DefaultConstructable { + // only default constructor +} diff --git a/test/cuchaz/enigma/inputs/constructors/SubClass.java b/test/cuchaz/enigma/inputs/constructors/SubClass.java new file mode 100644 index 00000000..fecfa2b5 --- /dev/null +++ b/test/cuchaz/enigma/inputs/constructors/SubClass.java @@ -0,0 +1,28 @@ +package cuchaz.enigma.inputs.constructors; + +// none/d extends none/a +public class SubClass extends BaseClass { + + // ()V + public SubClass() { + // none/a.()V + } + + // (I)V + public SubClass(int num) { + // ()V + this(); + System.out.println("SubClass " + num); + } + + // (II)V + public SubClass(int a, int b) { + // (I)V + this(a + b); + } + + // (III)V + public SubClass(int a, int b, int c) { + // none/a.()V + } +} diff --git a/test/cuchaz/enigma/inputs/constructors/SubSubClass.java b/test/cuchaz/enigma/inputs/constructors/SubSubClass.java new file mode 100644 index 00000000..ab84161b --- /dev/null +++ b/test/cuchaz/enigma/inputs/constructors/SubSubClass.java @@ -0,0 +1,11 @@ +package cuchaz.enigma.inputs.constructors; + +// none/e extends none/d +public class SubSubClass extends SubClass { + + // (I)V + public SubSubClass(int i) { + // none/c.(I)V + super(i); + } +} diff --git a/test/cuchaz/enigma/inputs/inheritanceTree/BaseClass.java b/test/cuchaz/enigma/inputs/inheritanceTree/BaseClass.java new file mode 100644 index 00000000..5b416c41 --- /dev/null +++ b/test/cuchaz/enigma/inputs/inheritanceTree/BaseClass.java @@ -0,0 +1,21 @@ +package cuchaz.enigma.inputs.inheritanceTree; + +// none/a +public abstract class BaseClass { + + // a + private String m_name; + + // (Ljava/lang/String;)V + protected BaseClass(String name) { + m_name = name; + } + + // a()Ljava/lang/String; + public String getName() { + return m_name; + } + + // a()V + public abstract void doBaseThings(); +} diff --git a/test/cuchaz/enigma/inputs/inheritanceTree/SubclassA.java b/test/cuchaz/enigma/inputs/inheritanceTree/SubclassA.java new file mode 100644 index 00000000..7a99d516 --- /dev/null +++ b/test/cuchaz/enigma/inputs/inheritanceTree/SubclassA.java @@ -0,0 +1,11 @@ +package cuchaz.enigma.inputs.inheritanceTree; + +// none/b extends none/a +public abstract class SubclassA extends BaseClass { + + // (Ljava/lang/String;)V + protected SubclassA(String name) { + // call to none/a.(Ljava/lang/String)V + super(name); + } +} diff --git a/test/cuchaz/enigma/inputs/inheritanceTree/SubclassB.java b/test/cuchaz/enigma/inputs/inheritanceTree/SubclassB.java new file mode 100644 index 00000000..c9485d31 --- /dev/null +++ b/test/cuchaz/enigma/inputs/inheritanceTree/SubclassB.java @@ -0,0 +1,30 @@ +package cuchaz.enigma.inputs.inheritanceTree; + +// none/c extends none/a +public class SubclassB extends BaseClass { + + // a + private int m_numThings; + + // ()V + protected SubclassB() { + // none/a.(Ljava/lang/String;)V + super("B"); + + // access to a + m_numThings = 4; + } + + @Override + // a()V + public void doBaseThings() { + // call to none/a.a()Ljava/lang/String; + System.out.println("Base things by B! " + getName()); + } + + // b()V + public void doBThings() { + // access to a + System.out.println("" + m_numThings + " B things!"); + } +} diff --git a/test/cuchaz/enigma/inputs/inheritanceTree/SubsubclassAA.java b/test/cuchaz/enigma/inputs/inheritanceTree/SubsubclassAA.java new file mode 100644 index 00000000..afd03ac4 --- /dev/null +++ b/test/cuchaz/enigma/inputs/inheritanceTree/SubsubclassAA.java @@ -0,0 +1,24 @@ +package cuchaz.enigma.inputs.inheritanceTree; + +// none/d extends none/b +public class SubsubclassAA extends SubclassA { + + protected SubsubclassAA() { + // call to none/b.(Ljava/lang/String;)V + super("AA"); + } + + @Override + // a()Ljava/lang/String; + public String getName() { + // call to none/b.a()Ljava/lang/String; + return "subsub" + super.getName(); + } + + @Override + // a()V + public void doBaseThings() { + // call to none/d.a()Ljava/lang/String; + System.out.println("Base things by " + getName()); + } +} 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 00000000..f7118f63 --- /dev/null +++ b/test/cuchaz/enigma/inputs/innerClasses/A_Anonymous.java @@ -0,0 +1,14 @@ +package cuchaz.enigma.inputs.innerClasses; + +public class A_Anonymous { + + public void foo() { + Runnable runnable = new Runnable() { + @Override + public void run() { + // don't care + } + }; + runnable.run(); + } +} 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 00000000..42fba9a8 --- /dev/null +++ b/test/cuchaz/enigma/inputs/innerClasses/B_AnonymousWithScopeArgs.java @@ -0,0 +1,13 @@ +package cuchaz.enigma.inputs.innerClasses; + +public class B_AnonymousWithScopeArgs { + + public static void foo(final D_Simple arg) { + System.out.println(new Object() { + @Override + public String toString() { + return arg.toString(); + } + }); + } +} 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 00000000..8fa6c5b8 --- /dev/null +++ b/test/cuchaz/enigma/inputs/innerClasses/C_ConstructorArgs.java @@ -0,0 +1,20 @@ +package cuchaz.enigma.inputs.innerClasses; + +@SuppressWarnings("unused") +public class C_ConstructorArgs { + + class Inner { + + private int a; + + public Inner(int a) { + this.a = a; + } + } + + Inner i; + + public void foo() { + i = new Inner(5); + } +} 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 00000000..c4fc0ef9 --- /dev/null +++ b/test/cuchaz/enigma/inputs/innerClasses/D_Simple.java @@ -0,0 +1,8 @@ +package cuchaz.enigma.inputs.innerClasses; + +public class D_Simple { + + class Inner { + // nothing to do + } +} 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 00000000..e1de53cb --- /dev/null +++ b/test/cuchaz/enigma/inputs/innerClasses/E_AnonymousWithOuterAccess.java @@ -0,0 +1,21 @@ +package cuchaz.enigma.inputs.innerClasses; + +public class E_AnonymousWithOuterAccess { + + // reproduction of error case documented at: + // https://bitbucket.org/cuchaz/enigma/issue/61/stackoverflowerror-when-deobfuscating + + public Object makeInner() { + outerMethod(); + return new Object() { + @Override + public String toString() { + return outerMethod(); + } + }; + } + + private String outerMethod() { + return "foo"; + } +} diff --git a/test/cuchaz/enigma/inputs/loneClass/LoneClass.java b/test/cuchaz/enigma/inputs/loneClass/LoneClass.java new file mode 100644 index 00000000..18c716e9 --- /dev/null +++ b/test/cuchaz/enigma/inputs/loneClass/LoneClass.java @@ -0,0 +1,14 @@ +package cuchaz.enigma.inputs.loneClass; + +public class LoneClass { + + private String m_name; + + public LoneClass(String name) { + m_name = name; + } + + public String getName() { + return m_name; + } +} diff --git a/test/cuchaz/enigma/inputs/translation/A.java b/test/cuchaz/enigma/inputs/translation/A.java new file mode 100644 index 00000000..b8aaf11e --- /dev/null +++ b/test/cuchaz/enigma/inputs/translation/A.java @@ -0,0 +1,8 @@ +package cuchaz.enigma.inputs.translation; + +public class A { + + public int one; + public float two; + public String three; +} diff --git a/test/cuchaz/enigma/resources/translation.mappings b/test/cuchaz/enigma/resources/translation.mappings new file mode 100644 index 00000000..70755bf6 --- /dev/null +++ b/test/cuchaz/enigma/resources/translation.mappings @@ -0,0 +1,4 @@ +CLASS none/a deobf/A + FIELD a one + FIELD b two + FIELD c three \ No newline at end of file -- cgit v1.2.3 From 31a1a418b04cd3e7b06cb50cb8674a2c25079f6c Mon Sep 17 00:00:00 2001 From: jeff Date: Sun, 8 Feb 2015 23:10:26 -0500 Subject: added types to fields --- test/cuchaz/enigma/EntryFactory.java | 9 +++++---- test/cuchaz/enigma/TestJarIndexInheritanceTree.java | 4 ++-- test/cuchaz/enigma/TestJarIndexLoneClass.java | 12 +++++++----- test/cuchaz/enigma/TestTranslator.java | 3 +++ test/cuchaz/enigma/resources/translation.mappings | 6 +++--- 5 files changed, 20 insertions(+), 14 deletions(-) (limited to 'test') diff --git a/test/cuchaz/enigma/EntryFactory.java b/test/cuchaz/enigma/EntryFactory.java index fa90779d..8c94bdf3 100644 --- a/test/cuchaz/enigma/EntryFactory.java +++ b/test/cuchaz/enigma/EntryFactory.java @@ -18,6 +18,7 @@ import cuchaz.enigma.mapping.ConstructorEntry; import cuchaz.enigma.mapping.FieldEntry; import cuchaz.enigma.mapping.MethodEntry; import cuchaz.enigma.mapping.Signature; +import cuchaz.enigma.mapping.Type; public class EntryFactory { @@ -25,12 +26,12 @@ public class EntryFactory { return new ClassEntry(name); } - public static FieldEntry newField(String className, String fieldName) { - return newField(newClass(className), fieldName); + public static FieldEntry newField(String className, String fieldName, String fieldType) { + return newField(newClass(className), fieldName, fieldType); } - public static FieldEntry newField(ClassEntry classEntry, String fieldName) { - return new FieldEntry(classEntry, fieldName); + public static FieldEntry newField(ClassEntry classEntry, String fieldName, String fieldType) { + return new FieldEntry(classEntry, fieldName, new Type(fieldType)); } public static MethodEntry newMethod(String className, String methodName, String methodSignature) { diff --git a/test/cuchaz/enigma/TestJarIndexInheritanceTree.java b/test/cuchaz/enigma/TestJarIndexInheritanceTree.java index 1d6e5a55..349d33b1 100644 --- a/test/cuchaz/enigma/TestJarIndexInheritanceTree.java +++ b/test/cuchaz/enigma/TestJarIndexInheritanceTree.java @@ -37,8 +37,8 @@ public class TestJarIndexInheritanceTree { private ClassEntry m_subClassA = newClass("none/b"); private ClassEntry m_subClassAA = newClass("none/d"); private ClassEntry m_subClassB = newClass("none/c"); - private FieldEntry m_nameField = new FieldEntry(m_baseClass, "a"); - private FieldEntry m_numThingsField = new FieldEntry(m_subClassB, "a"); + private FieldEntry m_nameField = newField(m_baseClass, "a", "Ljava/lang/String;"); + private FieldEntry m_numThingsField = newField(m_subClassB, "a", "I"); public TestJarIndexInheritanceTree() throws Exception { diff --git a/test/cuchaz/enigma/TestJarIndexLoneClass.java b/test/cuchaz/enigma/TestJarIndexLoneClass.java index c6a9e550..c0ac8d7d 100644 --- a/test/cuchaz/enigma/TestJarIndexLoneClass.java +++ b/test/cuchaz/enigma/TestJarIndexLoneClass.java @@ -64,9 +64,10 @@ public class TestJarIndexLoneClass { @Test public void access() { - assertThat(m_index.getAccess(newField("none/a", "a")), is(Access.Private)); + assertThat(m_index.getAccess(newField("none/a", "a", "Ljava/lang/String;")), is(Access.Private)); assertThat(m_index.getAccess(newMethod("none/a", "a", "()Ljava/lang/String;")), is(Access.Public)); - assertThat(m_index.getAccess(newField("none/a", "b")), is(nullValue())); + assertThat(m_index.getAccess(newField("none/a", "b", "Ljava/lang/String;")), is(nullValue())); + assertThat(m_index.getAccess(newField("none/a", "a", "LFoo;")), is(nullValue())); } @Test @@ -110,7 +111,7 @@ public class TestJarIndexLoneClass { @Test @SuppressWarnings("unchecked") public void fieldReferences() { - FieldEntry source = newField("none/a", "a"); + FieldEntry source = newField("none/a", "a", "Ljava/lang/String;"); Collection> references = m_index.getFieldReferences(source); assertThat(references, containsInAnyOrder( newFieldReferenceByConstructor(source, "none/a", "(Ljava/lang/String;)V"), @@ -157,8 +158,9 @@ public class TestJarIndexLoneClass { public void contains() { assertThat(m_index.containsObfClass(newClass("none/a")), is(true)); assertThat(m_index.containsObfClass(newClass("none/b")), is(false)); - assertThat(m_index.containsObfField(newField("none/a", "a")), is(true)); - assertThat(m_index.containsObfField(newField("none/a", "b")), is(false)); + assertThat(m_index.containsObfField(newField("none/a", "a", "Ljava/lang/String;")), is(true)); + assertThat(m_index.containsObfField(newField("none/a", "b", "Ljava/lang/String;")), is(false)); + assertThat(m_index.containsObfField(newField("none/a", "a", "LFoo;")), is(false)); assertThat(m_index.containsObfBehavior(newMethod("none/a", "a", "()Ljava/lang/String;")), is(true)); assertThat(m_index.containsObfBehavior(newMethod("none/a", "b", "()Ljava/lang/String;")), is(false)); } diff --git a/test/cuchaz/enigma/TestTranslator.java b/test/cuchaz/enigma/TestTranslator.java index 290f6f04..f91c5852 100644 --- a/test/cuchaz/enigma/TestTranslator.java +++ b/test/cuchaz/enigma/TestTranslator.java @@ -35,5 +35,8 @@ public class TestTranslator { throws Exception { Translator translator = m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating); assertThat(translator.translateEntry(newClass("none/a")), is(newClass("deobf/A"))); + assertThat(translator.translateEntry(newField("none/a", "a", "I")), is(newField("deobf/A", "one", "I"))); + assertThat(translator.translateEntry(newField("none/a", "a", "F")), is(newField("deobf/A", "two", "F"))); + assertThat(translator.translateEntry(newField("none/a", "a", "Ljava/lang/String;")), is(newField("deobf/A", "three", "Ljava/lang/String;"))); } } diff --git a/test/cuchaz/enigma/resources/translation.mappings b/test/cuchaz/enigma/resources/translation.mappings index 70755bf6..c71493e9 100644 --- a/test/cuchaz/enigma/resources/translation.mappings +++ b/test/cuchaz/enigma/resources/translation.mappings @@ -1,4 +1,4 @@ CLASS none/a deobf/A - FIELD a one - FIELD b two - FIELD c three \ No newline at end of file + FIELD a one I + FIELD a two F + FIELD a three Ljava/lang/String; \ No newline at end of file -- cgit v1.2.3 From af1041731c8c0ce1846ff7e7b6052ed7327a5dbc Mon Sep 17 00:00:00 2001 From: jeff Date: Mon, 9 Feb 2015 22:23:45 -0500 Subject: fix translation issues, particularly with fields --- test/cuchaz/enigma/EntryFactory.java | 68 ----------------- test/cuchaz/enigma/TestEntryFactory.java | 68 +++++++++++++++++ .../enigma/TestJarIndexConstructorReferences.java | 2 +- .../cuchaz/enigma/TestJarIndexInheritanceTree.java | 2 +- test/cuchaz/enigma/TestJarIndexLoneClass.java | 5 +- test/cuchaz/enigma/TestTokensConstructors.java | 2 +- test/cuchaz/enigma/TestTranslator.java | 86 +++++++++++++++++++--- test/cuchaz/enigma/TestType.java | 2 +- test/cuchaz/enigma/inputs/translation/A.java | 8 -- test/cuchaz/enigma/inputs/translation/A_Basic.java | 22 ++++++ .../enigma/inputs/translation/B_BaseClass.java | 15 ++++ .../enigma/inputs/translation/C_SubClass.java | 17 +++++ test/cuchaz/enigma/resources/translation.mappings | 23 +++++- 13 files changed, 221 insertions(+), 99 deletions(-) delete mode 100644 test/cuchaz/enigma/EntryFactory.java create mode 100644 test/cuchaz/enigma/TestEntryFactory.java delete mode 100644 test/cuchaz/enigma/inputs/translation/A.java create mode 100644 test/cuchaz/enigma/inputs/translation/A_Basic.java create mode 100644 test/cuchaz/enigma/inputs/translation/B_BaseClass.java create mode 100644 test/cuchaz/enigma/inputs/translation/C_SubClass.java (limited to 'test') diff --git a/test/cuchaz/enigma/EntryFactory.java b/test/cuchaz/enigma/EntryFactory.java deleted file mode 100644 index 8c94bdf3..00000000 --- a/test/cuchaz/enigma/EntryFactory.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 Jeff Martin.\ - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Public License v3.0 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/gpl.html - * - * Contributors: - * Jeff Martin - initial API and implementation - ******************************************************************************/ -package cuchaz.enigma; - -import cuchaz.enigma.analysis.EntryReference; -import cuchaz.enigma.mapping.BehaviorEntry; -import cuchaz.enigma.mapping.ClassEntry; -import cuchaz.enigma.mapping.ConstructorEntry; -import cuchaz.enigma.mapping.FieldEntry; -import cuchaz.enigma.mapping.MethodEntry; -import cuchaz.enigma.mapping.Signature; -import cuchaz.enigma.mapping.Type; - -public class EntryFactory { - - public static ClassEntry newClass(String name) { - return new ClassEntry(name); - } - - public static FieldEntry newField(String className, String fieldName, String fieldType) { - return newField(newClass(className), fieldName, fieldType); - } - - public static FieldEntry newField(ClassEntry classEntry, String fieldName, String fieldType) { - return new FieldEntry(classEntry, fieldName, new Type(fieldType)); - } - - public static MethodEntry newMethod(String className, String methodName, String methodSignature) { - return newMethod(newClass(className), methodName, methodSignature); - } - - public static MethodEntry newMethod(ClassEntry classEntry, String methodName, String methodSignature) { - return new MethodEntry(classEntry, methodName, new Signature(methodSignature)); - } - - public static ConstructorEntry newConstructor(String className, String signature) { - return newConstructor(newClass(className), signature); - } - - public static ConstructorEntry newConstructor(ClassEntry classEntry, String signature) { - return new ConstructorEntry(classEntry, new Signature(signature)); - } - - public static EntryReference newFieldReferenceByMethod(FieldEntry fieldEntry, String callerClassName, String callerName, String callerSignature) { - return new EntryReference(fieldEntry, "", newMethod(callerClassName, callerName, callerSignature)); - } - - public static EntryReference newFieldReferenceByConstructor(FieldEntry fieldEntry, String callerClassName, String callerSignature) { - return new EntryReference(fieldEntry, "", newConstructor(callerClassName, callerSignature)); - } - - public static EntryReference newBehaviorReferenceByMethod(BehaviorEntry behaviorEntry, String callerClassName, String callerName, String callerSignature) { - return new EntryReference(behaviorEntry, "", newMethod(callerClassName, callerName, callerSignature)); - } - - public static EntryReference newBehaviorReferenceByConstructor(BehaviorEntry behaviorEntry, String callerClassName, String callerSignature) { - return new EntryReference(behaviorEntry, "", newConstructor(callerClassName, callerSignature)); - } -} diff --git a/test/cuchaz/enigma/TestEntryFactory.java b/test/cuchaz/enigma/TestEntryFactory.java new file mode 100644 index 00000000..754f3081 --- /dev/null +++ b/test/cuchaz/enigma/TestEntryFactory.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2014 Jeff Martin.\ + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Public License v3.0 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/gpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ +package cuchaz.enigma; + +import cuchaz.enigma.analysis.EntryReference; +import cuchaz.enigma.mapping.BehaviorEntry; +import cuchaz.enigma.mapping.ClassEntry; +import cuchaz.enigma.mapping.ConstructorEntry; +import cuchaz.enigma.mapping.FieldEntry; +import cuchaz.enigma.mapping.MethodEntry; +import cuchaz.enigma.mapping.Signature; +import cuchaz.enigma.mapping.Type; + +public class TestEntryFactory { + + public static ClassEntry newClass(String name) { + return new ClassEntry(name); + } + + public static FieldEntry newField(String className, String fieldName, String fieldType) { + return newField(newClass(className), fieldName, fieldType); + } + + public static FieldEntry newField(ClassEntry classEntry, String fieldName, String fieldType) { + return new FieldEntry(classEntry, fieldName, new Type(fieldType)); + } + + public static MethodEntry newMethod(String className, String methodName, String methodSignature) { + return newMethod(newClass(className), methodName, methodSignature); + } + + public static MethodEntry newMethod(ClassEntry classEntry, String methodName, String methodSignature) { + return new MethodEntry(classEntry, methodName, new Signature(methodSignature)); + } + + public static ConstructorEntry newConstructor(String className, String signature) { + return newConstructor(newClass(className), signature); + } + + public static ConstructorEntry newConstructor(ClassEntry classEntry, String signature) { + return new ConstructorEntry(classEntry, new Signature(signature)); + } + + public static EntryReference newFieldReferenceByMethod(FieldEntry fieldEntry, String callerClassName, String callerName, String callerSignature) { + return new EntryReference(fieldEntry, "", newMethod(callerClassName, callerName, callerSignature)); + } + + public static EntryReference newFieldReferenceByConstructor(FieldEntry fieldEntry, String callerClassName, String callerSignature) { + return new EntryReference(fieldEntry, "", newConstructor(callerClassName, callerSignature)); + } + + public static EntryReference newBehaviorReferenceByMethod(BehaviorEntry behaviorEntry, String callerClassName, String callerName, String callerSignature) { + return new EntryReference(behaviorEntry, "", newMethod(callerClassName, callerName, callerSignature)); + } + + public static EntryReference newBehaviorReferenceByConstructor(BehaviorEntry behaviorEntry, String callerClassName, String callerSignature) { + return new EntryReference(behaviorEntry, "", newConstructor(callerClassName, callerSignature)); + } +} diff --git a/test/cuchaz/enigma/TestJarIndexConstructorReferences.java b/test/cuchaz/enigma/TestJarIndexConstructorReferences.java index 22812fea..e1a30226 100644 --- a/test/cuchaz/enigma/TestJarIndexConstructorReferences.java +++ b/test/cuchaz/enigma/TestJarIndexConstructorReferences.java @@ -10,7 +10,7 @@ ******************************************************************************/ package cuchaz.enigma; -import static cuchaz.enigma.EntryFactory.*; +import static cuchaz.enigma.TestEntryFactory.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/test/cuchaz/enigma/TestJarIndexInheritanceTree.java b/test/cuchaz/enigma/TestJarIndexInheritanceTree.java index 349d33b1..6e2c1ad3 100644 --- a/test/cuchaz/enigma/TestJarIndexInheritanceTree.java +++ b/test/cuchaz/enigma/TestJarIndexInheritanceTree.java @@ -10,7 +10,7 @@ ******************************************************************************/ package cuchaz.enigma; -import static cuchaz.enigma.EntryFactory.*; +import static cuchaz.enigma.TestEntryFactory.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/test/cuchaz/enigma/TestJarIndexLoneClass.java b/test/cuchaz/enigma/TestJarIndexLoneClass.java index c0ac8d7d..768284f9 100644 --- a/test/cuchaz/enigma/TestJarIndexLoneClass.java +++ b/test/cuchaz/enigma/TestJarIndexLoneClass.java @@ -11,7 +11,7 @@ ******************************************************************************/ package cuchaz.enigma; -import static cuchaz.enigma.EntryFactory.*; +import static cuchaz.enigma.TestEntryFactory.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; @@ -96,8 +96,7 @@ public class TestJarIndexLoneClass { @Test public void methodImplementations() { MethodEntry source = newMethod("none/a", "a", "()Ljava/lang/String;"); - MethodImplementationsTreeNode node = m_index.getMethodImplementations(new Translator(), source); - assertThat(node, is(nullValue())); + assertThat(m_index.getMethodImplementations(new Translator(), source), is(empty())); } @Test diff --git a/test/cuchaz/enigma/TestTokensConstructors.java b/test/cuchaz/enigma/TestTokensConstructors.java index 6758d2a7..a563f832 100644 --- a/test/cuchaz/enigma/TestTokensConstructors.java +++ b/test/cuchaz/enigma/TestTokensConstructors.java @@ -10,7 +10,7 @@ ******************************************************************************/ package cuchaz.enigma; -import static cuchaz.enigma.EntryFactory.*; +import static cuchaz.enigma.TestEntryFactory.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; diff --git a/test/cuchaz/enigma/TestTranslator.java b/test/cuchaz/enigma/TestTranslator.java index f91c5852..3fe1680f 100644 --- a/test/cuchaz/enigma/TestTranslator.java +++ b/test/cuchaz/enigma/TestTranslator.java @@ -1,6 +1,6 @@ package cuchaz.enigma; -import static cuchaz.enigma.EntryFactory.*; +import static cuchaz.enigma.TestEntryFactory.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; @@ -8,8 +8,10 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.util.jar.JarFile; +import org.junit.BeforeClass; import org.junit.Test; +import cuchaz.enigma.mapping.Entry; import cuchaz.enigma.mapping.Mappings; import cuchaz.enigma.mapping.MappingsReader; import cuchaz.enigma.mapping.TranslationDirection; @@ -18,25 +20,85 @@ import cuchaz.enigma.mapping.Translator; public class TestTranslator { - private Deobfuscator m_deobfuscator; - private Mappings m_mappings; + private static Deobfuscator m_deobfuscator; + private static Mappings m_mappings; + private static Translator m_deobfTranslator; + private static Translator m_obfTranslator; - public TestTranslator() + @BeforeClass + public static void beforeClass() throws Exception { m_deobfuscator = new Deobfuscator(new JarFile("build/testTranslation.obf.jar")); - try (InputStream in = getClass().getResourceAsStream("/cuchaz/enigma/resources/translation.mappings")) { + try (InputStream in = TestTranslator.class.getResourceAsStream("/cuchaz/enigma/resources/translation.mappings")) { m_mappings = new MappingsReader().read(new InputStreamReader(in)); m_deobfuscator.setMappings(m_mappings); + m_deobfTranslator = m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating); + m_obfTranslator = m_deobfuscator.getTranslator(TranslationDirection.Obfuscating); } } @Test - public void deobfuscatingTranslations() - throws Exception { - Translator translator = m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating); - assertThat(translator.translateEntry(newClass("none/a")), is(newClass("deobf/A"))); - assertThat(translator.translateEntry(newField("none/a", "a", "I")), is(newField("deobf/A", "one", "I"))); - assertThat(translator.translateEntry(newField("none/a", "a", "F")), is(newField("deobf/A", "two", "F"))); - assertThat(translator.translateEntry(newField("none/a", "a", "Ljava/lang/String;")), is(newField("deobf/A", "three", "Ljava/lang/String;"))); + public void basicClasses() { + assertMapping(newClass("none/a"), newClass("deobf/A_Basic")); + assertMapping(newClass("none/b"), newClass("deobf/B_BaseClass")); + assertMapping(newClass("none/c"), newClass("deobf/C_SubClass")); + } + + @Test + public void basicFields() { + assertMapping(newField("none/a", "a", "I"), newField("deobf/A_Basic", "f1", "I")); + assertMapping(newField("none/a", "a", "F"), newField("deobf/A_Basic", "f2", "F")); + assertMapping(newField("none/a", "a", "Ljava/lang/String;"), newField("deobf/A_Basic", "f3", "Ljava/lang/String;")); + } + + @Test + public void basicMethods() { + assertMapping(newMethod("none/a", "a", "()V"), newMethod("deobf/A_Basic", "m1", "()V")); + assertMapping(newMethod("none/a", "a", "()I"), newMethod("deobf/A_Basic", "m2", "()I")); + assertMapping(newMethod("none/a", "a", "(I)V"), newMethod("deobf/A_Basic", "m3", "(I)V")); + assertMapping(newMethod("none/a", "a", "(I)I"), newMethod("deobf/A_Basic", "m4", "(I)I")); + } + + // TODO: basic constructors + + @Test + public void inheritanceFields() { + assertMapping(newField("none/b", "a", "I"), newField("deobf/B_BaseClass", "f1", "I")); + assertMapping(newField("none/b", "a", "C"), newField("deobf/B_BaseClass", "f2", "C")); + assertMapping(newField("none/c", "b", "I"), newField("deobf/C_SubClass", "f3", "I")); + assertMapping(newField("none/c", "c", "I"), newField("deobf/C_SubClass", "f4", "I")); + } + + @Test + public void inheritanceFieldsShadowing() { + assertMapping(newField("none/c", "b", "C"), newField("deobf/C_SubClass", "f2", "C")); + } + + @Test + public void inheritanceFieldsBySubClass() { + assertMapping(newField("none/c", "a", "I"), newField("deobf/C_SubClass", "f1", "I")); + // NOTE: can't reference b.C by subclass since it's shadowed + } + + @Test + public void inheritanceMethods() { + assertMapping(newMethod("none/b", "a", "()I"), newMethod("deobf/B_BaseClass", "m1", "()I")); + assertMapping(newMethod("none/b", "b", "()I"), newMethod("deobf/B_BaseClass", "m2", "()I")); + assertMapping(newMethod("none/c", "c", "()I"), newMethod("deobf/C_SubClass", "m3", "()I")); + } + + @Test + public void inheritanceMethodsOverrides() { + assertMapping(newMethod("none/c", "a", "()I"), newMethod("deobf/C_SubClass", "m1", "()I")); + } + + @Test + public void inheritanceMethodsBySubClass() { + assertMapping(newMethod("none/c", "b", "()I"), newMethod("deobf/C_SubClass", "m2", "()I")); + } + + private void assertMapping(Entry obf, Entry deobf) { + assertThat(m_deobfTranslator.translateEntry(obf), is(deobf)); + assertThat(m_obfTranslator.translateEntry(deobf), is(obf)); } } diff --git a/test/cuchaz/enigma/TestType.java b/test/cuchaz/enigma/TestType.java index 7c3cebe2..93f864b0 100644 --- a/test/cuchaz/enigma/TestType.java +++ b/test/cuchaz/enigma/TestType.java @@ -7,7 +7,7 @@ import static org.hamcrest.Matchers.*; import cuchaz.enigma.mapping.Type; -import static cuchaz.enigma.EntryFactory.*; +import static cuchaz.enigma.TestEntryFactory.*; public class TestType { diff --git a/test/cuchaz/enigma/inputs/translation/A.java b/test/cuchaz/enigma/inputs/translation/A.java deleted file mode 100644 index b8aaf11e..00000000 --- a/test/cuchaz/enigma/inputs/translation/A.java +++ /dev/null @@ -1,8 +0,0 @@ -package cuchaz.enigma.inputs.translation; - -public class A { - - public int one; - public float two; - public String three; -} 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 00000000..89307630 --- /dev/null +++ b/test/cuchaz/enigma/inputs/translation/A_Basic.java @@ -0,0 +1,22 @@ +package cuchaz.enigma.inputs.translation; + +public class A_Basic { + + public int one; + public float two; + public String three; + + public void m1() { + } + + public int m2() { + return 42; + } + + public void m3(int a1) { + } + + public int m4(int a1) { + return 5; // chosen by fair die roll, guaranteed to be random + } +} 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 00000000..44fbc8db --- /dev/null +++ b/test/cuchaz/enigma/inputs/translation/B_BaseClass.java @@ -0,0 +1,15 @@ +package cuchaz.enigma.inputs.translation; + +public class B_BaseClass { + + public int f1; + public char f2; + + public int m1() { + return 5; + } + + public int m2() { + return 42; + } +} 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 00000000..8fe0b799 --- /dev/null +++ b/test/cuchaz/enigma/inputs/translation/C_SubClass.java @@ -0,0 +1,17 @@ +package cuchaz.enigma.inputs.translation; + +public class C_SubClass extends B_BaseClass { + + public char f2; // shadows B_BaseClass.f2 + public int f3; + public int f4; + + @Override + public int m1() { + return 32; + } + + public int m3() { + return 7; + } +} diff --git a/test/cuchaz/enigma/resources/translation.mappings b/test/cuchaz/enigma/resources/translation.mappings index c71493e9..d87d437c 100644 --- a/test/cuchaz/enigma/resources/translation.mappings +++ b/test/cuchaz/enigma/resources/translation.mappings @@ -1,4 +1,19 @@ -CLASS none/a deobf/A - FIELD a one I - FIELD a two F - FIELD a three Ljava/lang/String; \ No newline at end of file +CLASS none/a deobf/A_Basic + FIELD a f1 I + FIELD a f2 F + FIELD a f3 Ljava/lang/String; + METHOD a m1 ()V + METHOD a m2 ()I + METHOD a m3 (I)V + METHOD a m4 (I)I +CLASS none/b deobf/B_BaseClass + FIELD a f1 I + FIELD a f2 C + METHOD a m1 ()I + METHOD b m2 ()I +CLASS none/c deobf/C_SubClass + FIELD b f2 C + FIELD b f3 I + FIELD c f4 I + METHOD a m1 ()I + METHOD c m3 ()I -- cgit v1.2.3 From ab6de199201f3cb292b986b2803d7d30b1485a47 Mon Sep 17 00:00:00 2001 From: jeff Date: Mon, 9 Feb 2015 23:31:24 -0500 Subject: work around bad tokens generated by procyon for now --- .../enigma/inputs/translation/D_AnonymousTesting.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test/cuchaz/enigma/inputs/translation/D_AnonymousTesting.java (limited to 'test') 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 00000000..a1166e20 --- /dev/null +++ b/test/cuchaz/enigma/inputs/translation/D_AnonymousTesting.java @@ -0,0 +1,18 @@ +package cuchaz.enigma.inputs.translation; + +import java.util.ArrayList; +import java.util.List; + +public class D_AnonymousTesting { + + public List getObjs() { + List objs = new ArrayList(); + objs.add(new Object() { + @Override + public String toString() { + return "Object!"; + } + }); + return objs; + } +} -- cgit v1.2.3 From 2b3c5c52865b40adfa93910d41738242f17338d4 Mon Sep 17 00:00:00 2001 From: jeff Date: Tue, 10 Feb 2015 22:10:16 -0500 Subject: add BRIDGE flag to bridge methods --- .../enigma/inputs/translation/E_Bridges.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 test/cuchaz/enigma/inputs/translation/E_Bridges.java (limited to 'test') 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 00000000..dac50d39 --- /dev/null +++ b/test/cuchaz/enigma/inputs/translation/E_Bridges.java @@ -0,0 +1,22 @@ +package cuchaz.enigma.inputs.translation; + +import java.util.Iterator; + + +public class E_Bridges implements Iterator { + + @Override + public boolean hasNext() { + return false; + } + + @Override + public String next() { + // the compiler will generate a bridge for this method + return "foo"; + } + + @Override + public void remove() { + } +} -- cgit v1.2.3 From 6044c91079ae416ecaff2412f8ca8653f39e6f83 Mon Sep 17 00:00:00 2001 From: jeff Date: Tue, 10 Feb 2015 22:51:55 -0500 Subject: black list Object methods from deobfuscation --- .../enigma/inputs/translation/F_ObjectMethods.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 test/cuchaz/enigma/inputs/translation/F_ObjectMethods.java (limited to 'test') 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 00000000..4e091797 --- /dev/null +++ b/test/cuchaz/enigma/inputs/translation/F_ObjectMethods.java @@ -0,0 +1,19 @@ +package cuchaz.enigma.inputs.translation; + +public class F_ObjectMethods { + + public void callEmAll() + throws Throwable { + clone(); + equals(this); + finalize(); + getClass(); + hashCode(); + notify(); + notifyAll(); + toString(); + wait(); + wait(0); + wait(0, 0); + } +} -- cgit v1.2.3 From 1bddb51a8370f96af2dfd61e75d72b155b71923e Mon Sep 17 00:00:00 2001 From: jeff Date: Tue, 10 Feb 2015 23:26:33 -0500 Subject: repackage as v0.7b --- test/cuchaz/enigma/TestSourceIndex.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/cuchaz/enigma/TestSourceIndex.java b/test/cuchaz/enigma/TestSourceIndex.java index 357acb62..96a8923b 100644 --- a/test/cuchaz/enigma/TestSourceIndex.java +++ b/test/cuchaz/enigma/TestSourceIndex.java @@ -24,7 +24,7 @@ import cuchaz.enigma.mapping.ClassEntry; public class TestSourceIndex { // TEMP - //@Test + @Test public void indexEverything() throws Exception { Deobfuscator deobfuscator = new Deobfuscator(new JarFile("input/1.8.jar")); -- cgit v1.2.3 From 2dc7428e37bdd7a119f53d02ce157675509b0d63 Mon Sep 17 00:00:00 2001 From: jeff Date: Mon, 23 Feb 2015 23:29:22 -0500 Subject: lots of work in better handling of inner classes also working on recognizing unobfuscated and deobfuscated jars (needed for M3L) --- test/cuchaz/enigma/TestInnerClasses.java | 67 ++++++++++++++++++---- test/cuchaz/enigma/TestJarIndexLoneClass.java | 7 +-- test/cuchaz/enigma/TestTranslator.java | 36 ++++++++++++ .../enigma/inputs/innerClasses/F_ClassTree.java | 20 +++++++ .../enigma/inputs/translation/F_ObjectMethods.java | 19 ------ .../enigma/inputs/translation/G_ObjectMethods.java | 19 ++++++ .../enigma/inputs/translation/H_OuterClass.java | 26 +++++++++ .../enigma/inputs/translation/M_NamelessClass.java | 26 +++++++++ test/cuchaz/enigma/resources/translation.mappings | 12 ++++ 9 files changed, 197 insertions(+), 35 deletions(-) create mode 100644 test/cuchaz/enigma/inputs/innerClasses/F_ClassTree.java delete mode 100644 test/cuchaz/enigma/inputs/translation/F_ObjectMethods.java create mode 100644 test/cuchaz/enigma/inputs/translation/G_ObjectMethods.java create mode 100644 test/cuchaz/enigma/inputs/translation/H_OuterClass.java create mode 100644 test/cuchaz/enigma/inputs/translation/M_NamelessClass.java (limited to 'test') diff --git a/test/cuchaz/enigma/TestInnerClasses.java b/test/cuchaz/enigma/TestInnerClasses.java index 2e16a330..2eb5accc 100644 --- a/test/cuchaz/enigma/TestInnerClasses.java +++ b/test/cuchaz/enigma/TestInnerClasses.java @@ -18,23 +18,30 @@ import java.util.jar.JarFile; import org.junit.Test; +import static cuchaz.enigma.TestEntryFactory.*; + import cuchaz.enigma.analysis.JarIndex; +import cuchaz.enigma.mapping.ClassEntry; public class TestInnerClasses { private JarIndex m_index; private Deobfuscator m_deobfuscator; - private static final String AnonymousOuter = "none/a"; - private static final String AnonymousInner = "b"; - private static final String SimpleOuter = "none/g"; - private static final String SimpleInner = "h"; - private static final String ConstructorArgsOuter = "none/e"; - private static final String ConstructorArgsInner = "f"; - private static final String AnonymousWithScopeArgsOuter = "none/c"; - private static final String AnonymousWithScopeArgsInner = "d"; - private static final String AnonymousWithOuterAccessOuter = "none/i"; - private static final String AnonymousWithOuterAccessInner = "j"; + private static final ClassEntry AnonymousOuter = newClass("none/a"); + private static final ClassEntry AnonymousInner = newClass("none/b"); + private static final ClassEntry SimpleOuter = newClass("none/g"); + private static final ClassEntry SimpleInner = newClass("none/h"); + private static final ClassEntry ConstructorArgsOuter = newClass("none/e"); + private static final ClassEntry ConstructorArgsInner = newClass("none/f"); + private static final ClassEntry AnonymousWithScopeArgsOuter = newClass("none/c"); + private static final ClassEntry AnonymousWithScopeArgsInner = newClass("none/d"); + private static final ClassEntry AnonymousWithOuterAccessOuter = newClass("none/i"); + private static final ClassEntry AnonymousWithOuterAccessInner = newClass("none/j"); + private static final ClassEntry ClassTreeRoot = newClass("none/k"); + private static final ClassEntry ClassTreeLevel1 = newClass("none/l"); + private static final ClassEntry ClassTreeLevel2 = newClass("none/m"); + private static final ClassEntry ClassTreeLevel3 = newClass("none/n"); public TestInnerClasses() throws Exception { @@ -84,7 +91,43 @@ public class TestInnerClasses { decompile(AnonymousWithOuterAccessOuter); } - private void decompile(String name) { - m_deobfuscator.getSourceTree(name); + @Test + public void classTree() { + + // root level + assertThat(m_index.containsObfClass(ClassTreeRoot), is(true)); + assertThat(m_index.getOuterClass(ClassTreeRoot), is(nullValue())); + assertThat(m_index.getInnerClasses(ClassTreeRoot), containsInAnyOrder(ClassTreeLevel1)); + + // level 1 + ClassEntry fullClassEntry = new ClassEntry(ClassTreeRoot.getName() + + "$" + ClassTreeLevel1.getSimpleName() + ); + assertThat(m_index.containsObfClass(fullClassEntry), is(true)); + assertThat(m_index.getOuterClass(ClassTreeLevel1), is(ClassTreeRoot)); + assertThat(m_index.getInnerClasses(ClassTreeLevel1), containsInAnyOrder(ClassTreeLevel2)); + + // level 2 + fullClassEntry = new ClassEntry(ClassTreeRoot.getName() + + "$" + ClassTreeLevel1.getSimpleName() + + "$" + ClassTreeLevel2.getSimpleName() + ); + assertThat(m_index.containsObfClass(fullClassEntry), is(true)); + assertThat(m_index.getOuterClass(ClassTreeLevel2), is(ClassTreeLevel1)); + assertThat(m_index.getInnerClasses(ClassTreeLevel2), containsInAnyOrder(ClassTreeLevel3)); + + // level 3 + fullClassEntry = new ClassEntry(ClassTreeRoot.getName() + + "$" + ClassTreeLevel1.getSimpleName() + + "$" + ClassTreeLevel2.getSimpleName() + + "$" + ClassTreeLevel3.getSimpleName() + ); + assertThat(m_index.containsObfClass(fullClassEntry), is(true)); + assertThat(m_index.getOuterClass(ClassTreeLevel3), is(ClassTreeLevel2)); + assertThat(m_index.getInnerClasses(ClassTreeLevel3), is(empty())); + } + + private void decompile(ClassEntry classEntry) { + m_deobfuscator.getSourceTree(classEntry.getName()); } } diff --git a/test/cuchaz/enigma/TestJarIndexLoneClass.java b/test/cuchaz/enigma/TestJarIndexLoneClass.java index 768284f9..0c126ad0 100644 --- a/test/cuchaz/enigma/TestJarIndexLoneClass.java +++ b/test/cuchaz/enigma/TestJarIndexLoneClass.java @@ -26,7 +26,6 @@ import cuchaz.enigma.analysis.ClassImplementationsTreeNode; import cuchaz.enigma.analysis.ClassInheritanceTreeNode; import cuchaz.enigma.analysis.EntryReference; import cuchaz.enigma.analysis.JarIndex; -import cuchaz.enigma.analysis.MethodImplementationsTreeNode; import cuchaz.enigma.analysis.MethodInheritanceTreeNode; import cuchaz.enigma.mapping.BehaviorEntry; import cuchaz.enigma.mapping.ClassEntry; @@ -125,17 +124,17 @@ public class TestJarIndexLoneClass { @Test public void innerClasses() { - assertThat(m_index.getInnerClasses("none/a"), is(empty())); + assertThat(m_index.getInnerClasses(newClass("none/a")), is(empty())); } @Test public void outerClass() { - assertThat(m_index.getOuterClass("a"), is(nullValue())); + assertThat(m_index.getOuterClass(newClass("a")), is(nullValue())); } @Test public void isAnonymousClass() { - assertThat(m_index.isAnonymousClass("none/a"), is(false)); + assertThat(m_index.isAnonymousClass(newClass("none/a")), is(false)); } @Test diff --git a/test/cuchaz/enigma/TestTranslator.java b/test/cuchaz/enigma/TestTranslator.java index 3fe1680f..02526050 100644 --- a/test/cuchaz/enigma/TestTranslator.java +++ b/test/cuchaz/enigma/TestTranslator.java @@ -97,8 +97,44 @@ public class TestTranslator { assertMapping(newMethod("none/c", "b", "()I"), newMethod("deobf/C_SubClass", "m2", "()I")); } + @Test + public void innerClasses() { + + // classes + assertMapping(newClass("none/h"), newClass("deobf/H_OuterClass")); + assertMapping(newClass("none/h$i"), newClass("deobf/H_OuterClass$I_InnerClass")); + assertMapping(newClass("none/h$i$j"), newClass("deobf/H_OuterClass$I_InnerClass$J_InnerInnerClass")); + assertMapping(newClass("none/h$k"), newClass("deobf/H_OuterClass$k")); + assertMapping(newClass("none/h$k$l"), newClass("deobf/H_OuterClass$k$L_NamedInnerClass")); + + // fields + assertMapping(newField("none/h$i", "a", "I"), newField("deobf/H_OuterClass$I_InnerClass", "f1", "I")); + assertMapping(newField("none/h$i", "a", "Ljava/lang/String;"), newField("deobf/H_OuterClass$I_InnerClass", "f2", "Ljava/lang/String;")); + assertMapping(newField("none/h$i$j", "a", "I"), newField("deobf/H_OuterClass$I_InnerClass$J_InnerInnerClass", "f3", "I")); + assertMapping(newField("none/h$k$l", "a", "I"), newField("deobf/H_OuterClass$k$L_NamedInnerClass", "f4", "I")); + + // methods + assertMapping(newMethod("none/h$i", "a", "()V"), newMethod("deobf/H_OuterClass$I_InnerClass", "m1", "()V")); + assertMapping(newMethod("none/h$i$j", "a", "()V"), newMethod("deobf/H_OuterClass$I_InnerClass$J_InnerInnerClass", "m2", "()V")); + } + + @Test + public void namelessClass() { + assertMapping(newClass("none/m"), newClass("none/m")); + } + private void assertMapping(Entry obf, Entry deobf) { assertThat(m_deobfTranslator.translateEntry(obf), is(deobf)); assertThat(m_obfTranslator.translateEntry(deobf), is(obf)); + + String deobfName = m_deobfTranslator.translate(obf); + if (deobfName != null) { + assertThat(deobfName, is(deobf.getName())); + } + + String obfName = m_obfTranslator.translate(deobf); + if (obfName != null) { + assertThat(obfName, is(obf.getName())); + } } } 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 00000000..6552d8a6 --- /dev/null +++ b/test/cuchaz/enigma/inputs/innerClasses/F_ClassTree.java @@ -0,0 +1,20 @@ +package cuchaz.enigma.inputs.innerClasses; + + +public class F_ClassTree { + + public class Level1 { + + public int f1; + + public class Level2 { + + public int f2; + + public class Level3 { + + public int f3; + } + } + } +} diff --git a/test/cuchaz/enigma/inputs/translation/F_ObjectMethods.java b/test/cuchaz/enigma/inputs/translation/F_ObjectMethods.java deleted file mode 100644 index 4e091797..00000000 --- a/test/cuchaz/enigma/inputs/translation/F_ObjectMethods.java +++ /dev/null @@ -1,19 +0,0 @@ -package cuchaz.enigma.inputs.translation; - -public class F_ObjectMethods { - - public void callEmAll() - throws Throwable { - clone(); - equals(this); - finalize(); - getClass(); - hashCode(); - notify(); - notifyAll(); - toString(); - wait(); - wait(0); - wait(0, 0); - } -} diff --git a/test/cuchaz/enigma/inputs/translation/G_ObjectMethods.java b/test/cuchaz/enigma/inputs/translation/G_ObjectMethods.java new file mode 100644 index 00000000..ebad5a38 --- /dev/null +++ b/test/cuchaz/enigma/inputs/translation/G_ObjectMethods.java @@ -0,0 +1,19 @@ +package cuchaz.enigma.inputs.translation; + +public class G_ObjectMethods { + + public void callEmAll() + throws Throwable { + clone(); + equals(this); + finalize(); + getClass(); + hashCode(); + notify(); + notifyAll(); + toString(); + wait(); + wait(0); + wait(0, 0); + } +} diff --git a/test/cuchaz/enigma/inputs/translation/H_OuterClass.java b/test/cuchaz/enigma/inputs/translation/H_OuterClass.java new file mode 100644 index 00000000..995c65d2 --- /dev/null +++ b/test/cuchaz/enigma/inputs/translation/H_OuterClass.java @@ -0,0 +1,26 @@ +package cuchaz.enigma.inputs.translation; + + +public class H_OuterClass { + + public class I_InnerClass { + + public int f1; + public String f2; + + public void m1() {} + + public class J_InnerInnerClass { + + public int f3; + + public void m2() {} + } + } + + public class K_NamelessClass { + public class L_NamedInnerClass { + public int f4; + } + } +} diff --git a/test/cuchaz/enigma/inputs/translation/M_NamelessClass.java b/test/cuchaz/enigma/inputs/translation/M_NamelessClass.java new file mode 100644 index 00000000..afc9a9a5 --- /dev/null +++ b/test/cuchaz/enigma/inputs/translation/M_NamelessClass.java @@ -0,0 +1,26 @@ +package cuchaz.enigma.inputs.translation; + + +public class M_NamelessClass { + + public class I_InnerClass { + + public int f1; + public String f2; + + public void m1() {} + + public class J_InnerInnerClass { + + public int f3; + + public void m2() {} + } + } + + public class K_NamelessClass { + public class L_NamedInnerClass { + public int f4; + } + } +} diff --git a/test/cuchaz/enigma/resources/translation.mappings b/test/cuchaz/enigma/resources/translation.mappings index d87d437c..5dffaf1d 100644 --- a/test/cuchaz/enigma/resources/translation.mappings +++ b/test/cuchaz/enigma/resources/translation.mappings @@ -17,3 +17,15 @@ CLASS none/c deobf/C_SubClass FIELD c f4 I METHOD a m1 ()I METHOD c m3 ()I +CLASS none/h deobf/H_OuterClass + CLASS none/i I_InnerClass + CLASS none/j J_InnerInnerClass + FIELD a f3 I + METHOD a m2 ()V + FIELD a f1 I + FIELD a f2 Ljava/lang/String; + METHOD a m1 ()V + CLASS none/k + CLASS none/l L_NamedInnerClass + FIELD a f4 I +CLASS none/m \ No newline at end of file -- cgit v1.2.3 From 4479acf3df4faf9daac93a396f5bba7cddb0759b Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 25 Feb 2015 00:12:04 -0500 Subject: more work getting inner class trees working in obf'd and deobf'd land --- test/cuchaz/enigma/TestJarIndexDeobfed.java | 52 ++++++++++++++++++++++ .../enigma/inputs/translation/M_NamelessClass.java | 10 +++-- 2 files changed, 58 insertions(+), 4 deletions(-) create mode 100644 test/cuchaz/enigma/TestJarIndexDeobfed.java (limited to 'test') diff --git a/test/cuchaz/enigma/TestJarIndexDeobfed.java b/test/cuchaz/enigma/TestJarIndexDeobfed.java new file mode 100644 index 00000000..f776e4f6 --- /dev/null +++ b/test/cuchaz/enigma/TestJarIndexDeobfed.java @@ -0,0 +1,52 @@ +package cuchaz.enigma; + + +import static cuchaz.enigma.TestEntryFactory.*; +import static org.hamcrest.MatcherAssert.*; +import static org.hamcrest.Matchers.*; + +import java.util.jar.JarFile; + +import org.junit.BeforeClass; +import org.junit.Test; + +import cuchaz.enigma.analysis.JarIndex; + + +public class TestJarIndexDeobfed { + + private static JarIndex m_index; + + @BeforeClass + public static void beforeClass() + throws Exception { + m_index = new JarIndex(); + m_index.indexJar(new JarFile("build/testTranslation.deobf.jar"), true); + } + + @Test + public void obfEntries() { + assertThat(m_index.getObfClassEntries(), containsInAnyOrder( + newClass("cuchaz/enigma/inputs/Keep"), + newClass("none/a"), + newClass("none/b"), + newClass("none/c"), + newClass("none/d"), + newClass("none/d$e"), + newClass("none/f"), + newClass("none/g"), + newClass("none/h"), + newClass("none/h$i"), + newClass("none/h$i$j"), + newClass("none/h$k"), + newClass("none/h$k$l"), + newClass("none/m"), + newClass("none/m$n"), + newClass("none/m$n$o"), + newClass("none/m$p"), + newClass("none/m$p$q"), + newClass("none/m$p$q$r"), + newClass("none/m$p$q$s") + )); + } +} diff --git a/test/cuchaz/enigma/inputs/translation/M_NamelessClass.java b/test/cuchaz/enigma/inputs/translation/M_NamelessClass.java index afc9a9a5..5d8acbc7 100644 --- a/test/cuchaz/enigma/inputs/translation/M_NamelessClass.java +++ b/test/cuchaz/enigma/inputs/translation/M_NamelessClass.java @@ -3,14 +3,14 @@ package cuchaz.enigma.inputs.translation; public class M_NamelessClass { - public class I_InnerClass { + public class N_InnerClass { public int f1; public String f2; public void m1() {} - public class J_InnerInnerClass { + public class O_InnerInnerClass { public int f3; @@ -18,9 +18,11 @@ public class M_NamelessClass { } } - public class K_NamelessClass { - public class L_NamedInnerClass { + public class P_NamelessClass { + public class Q_NamedInnerClass { public int f4; + public class R_AnotherInnerClass {} + public class S_YetAnotherInnerClass {} } } } -- cgit v1.2.3 From 9809078524bd3bd40fbf7aa411f6e0dca02fd009 Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 25 Feb 2015 22:42:34 -0500 Subject: fixed lots of issues with inner class reconstruction, particularly for inner class trees also fixed lots of issues with reading jars that aren't Minecraft. =P --- test/cuchaz/enigma/TestDeobfed.java | 79 +++++++++++++++++++++++++++++ test/cuchaz/enigma/TestJarIndexDeobfed.java | 52 ------------------- 2 files changed, 79 insertions(+), 52 deletions(-) create mode 100644 test/cuchaz/enigma/TestDeobfed.java delete mode 100644 test/cuchaz/enigma/TestJarIndexDeobfed.java (limited to 'test') diff --git a/test/cuchaz/enigma/TestDeobfed.java b/test/cuchaz/enigma/TestDeobfed.java new file mode 100644 index 00000000..3c2ae51d --- /dev/null +++ b/test/cuchaz/enigma/TestDeobfed.java @@ -0,0 +1,79 @@ +package cuchaz.enigma; + + +import static cuchaz.enigma.TestEntryFactory.*; +import static org.hamcrest.MatcherAssert.*; +import static org.hamcrest.Matchers.*; + +import java.util.jar.JarFile; + +import org.junit.BeforeClass; +import org.junit.Test; + +import cuchaz.enigma.analysis.JarIndex; + + +public class TestDeobfed { + + private static JarFile m_jar; + private static JarIndex m_index; + + @BeforeClass + public static void beforeClass() + throws Exception { + m_jar = new JarFile("build/testTranslation.deobf.jar"); + m_index = new JarIndex(); + m_index.indexJar(m_jar, true); + } + + @Test + public void obfEntries() { + assertThat(m_index.getObfClassEntries(), containsInAnyOrder( + newClass("cuchaz/enigma/inputs/Keep"), + newClass("none/a"), + newClass("none/b"), + newClass("none/c"), + newClass("none/d"), + newClass("none/d$e"), + newClass("none/f"), + newClass("none/g"), + newClass("none/h"), + newClass("none/h$i"), + newClass("none/h$i$j"), + newClass("none/h$k"), + newClass("none/h$k$l"), + newClass("none/m"), + newClass("none/m$n"), + newClass("none/m$n$o"), + newClass("none/m$p"), + newClass("none/m$p$q"), + newClass("none/m$p$q$r"), + newClass("none/m$p$q$s") + )); + } + + @Test + public void decompile() + throws Exception { + Deobfuscator deobfuscator = new Deobfuscator(m_jar); + deobfuscator.getSourceTree("none/a"); + deobfuscator.getSourceTree("none/b"); + deobfuscator.getSourceTree("none/c"); + deobfuscator.getSourceTree("none/d"); + deobfuscator.getSourceTree("none/d$e"); + deobfuscator.getSourceTree("none/f"); + deobfuscator.getSourceTree("none/g"); + deobfuscator.getSourceTree("none/h"); + deobfuscator.getSourceTree("none/h$i"); + deobfuscator.getSourceTree("none/h$i$j"); + deobfuscator.getSourceTree("none/h$k"); + deobfuscator.getSourceTree("none/h$k$l"); + deobfuscator.getSourceTree("none/m"); + deobfuscator.getSourceTree("none/m$n"); + deobfuscator.getSourceTree("none/m$n$o"); + deobfuscator.getSourceTree("none/m$p"); + deobfuscator.getSourceTree("none/m$p$q"); + deobfuscator.getSourceTree("none/m$p$q$r"); + deobfuscator.getSourceTree("none/m$p$q$s"); + } +} diff --git a/test/cuchaz/enigma/TestJarIndexDeobfed.java b/test/cuchaz/enigma/TestJarIndexDeobfed.java deleted file mode 100644 index f776e4f6..00000000 --- a/test/cuchaz/enigma/TestJarIndexDeobfed.java +++ /dev/null @@ -1,52 +0,0 @@ -package cuchaz.enigma; - - -import static cuchaz.enigma.TestEntryFactory.*; -import static org.hamcrest.MatcherAssert.*; -import static org.hamcrest.Matchers.*; - -import java.util.jar.JarFile; - -import org.junit.BeforeClass; -import org.junit.Test; - -import cuchaz.enigma.analysis.JarIndex; - - -public class TestJarIndexDeobfed { - - private static JarIndex m_index; - - @BeforeClass - public static void beforeClass() - throws Exception { - m_index = new JarIndex(); - m_index.indexJar(new JarFile("build/testTranslation.deobf.jar"), true); - } - - @Test - public void obfEntries() { - assertThat(m_index.getObfClassEntries(), containsInAnyOrder( - newClass("cuchaz/enigma/inputs/Keep"), - newClass("none/a"), - newClass("none/b"), - newClass("none/c"), - newClass("none/d"), - newClass("none/d$e"), - newClass("none/f"), - newClass("none/g"), - newClass("none/h"), - newClass("none/h$i"), - newClass("none/h$i$j"), - newClass("none/h$k"), - newClass("none/h$k$l"), - newClass("none/m"), - newClass("none/m$n"), - newClass("none/m$n$o"), - newClass("none/m$p"), - newClass("none/m$p$q"), - newClass("none/m$p$q$r"), - newClass("none/m$p$q$s") - )); - } -} -- cgit v1.2.3 From 2ff03cb72dccafd387776f5b0f91be1e8b056afb Mon Sep 17 00:00:00 2001 From: jeff Date: Sun, 15 Mar 2015 09:53:21 -0400 Subject: repackage for 0.9 beta --- test/cuchaz/enigma/TestSourceIndex.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/cuchaz/enigma/TestSourceIndex.java b/test/cuchaz/enigma/TestSourceIndex.java index 96a8923b..94bf941d 100644 --- a/test/cuchaz/enigma/TestSourceIndex.java +++ b/test/cuchaz/enigma/TestSourceIndex.java @@ -11,6 +11,7 @@ ******************************************************************************/ package cuchaz.enigma; +import java.io.File; import java.util.Set; import java.util.jar.JarFile; @@ -23,11 +24,13 @@ import cuchaz.enigma.mapping.ClassEntry; public class TestSourceIndex { - // TEMP @Test public void indexEverything() throws Exception { - Deobfuscator deobfuscator = new Deobfuscator(new JarFile("input/1.8.jar")); + + File home = new File(System.getProperty("user.home")); + File jarFile = new File(home, "/.minecraft/versions/1.8.3/1.8.3.jar"); + Deobfuscator deobfuscator = new Deobfuscator(new JarFile(jarFile)); // get all classes that aren't inner classes Set classEntries = Sets.newHashSet(); -- cgit v1.2.3 From c133e05b786ff5357931842581571c046f958c74 Mon Sep 17 00:00:00 2001 From: jeff Date: Mon, 16 Mar 2015 12:29:17 -0400 Subject: fix a zillion issues with inner classes --- test/cuchaz/enigma/TestDeobfed.java | 54 ++++++++++++---------- test/cuchaz/enigma/TestInnerClasses.java | 38 +++++++-------- test/cuchaz/enigma/TestSourceIndex.java | 2 +- test/cuchaz/enigma/TestTranslator.java | 29 +++++++----- .../enigma/inputs/translation/F_ObjectMethods.java | 19 ++++++++ .../enigma/inputs/translation/G_ObjectMethods.java | 19 -------- .../enigma/inputs/translation/G_OuterClass.java | 26 +++++++++++ .../enigma/inputs/translation/H_NamelessClass.java | 28 +++++++++++ .../enigma/inputs/translation/H_OuterClass.java | 26 ----------- .../enigma/inputs/translation/I_Generics.java | 25 ++++++++++ .../enigma/inputs/translation/M_NamelessClass.java | 28 ----------- test/cuchaz/enigma/resources/translation.mappings | 13 +++--- 12 files changed, 172 insertions(+), 135 deletions(-) create mode 100644 test/cuchaz/enigma/inputs/translation/F_ObjectMethods.java delete mode 100644 test/cuchaz/enigma/inputs/translation/G_ObjectMethods.java create mode 100644 test/cuchaz/enigma/inputs/translation/G_OuterClass.java create mode 100644 test/cuchaz/enigma/inputs/translation/H_NamelessClass.java delete mode 100644 test/cuchaz/enigma/inputs/translation/H_OuterClass.java create mode 100644 test/cuchaz/enigma/inputs/translation/I_Generics.java delete mode 100644 test/cuchaz/enigma/inputs/translation/M_NamelessClass.java (limited to 'test') diff --git a/test/cuchaz/enigma/TestDeobfed.java b/test/cuchaz/enigma/TestDeobfed.java index 3c2ae51d..ca349d7c 100644 --- a/test/cuchaz/enigma/TestDeobfed.java +++ b/test/cuchaz/enigma/TestDeobfed.java @@ -34,21 +34,24 @@ public class TestDeobfed { newClass("none/b"), newClass("none/c"), newClass("none/d"), - newClass("none/d$e"), + newClass("none/d$1"), + newClass("none/e"), newClass("none/f"), newClass("none/g"), + newClass("none/g$a"), + newClass("none/g$a$a"), + newClass("none/g$b"), + newClass("none/g$b$a"), newClass("none/h"), - newClass("none/h$i"), - newClass("none/h$i$j"), - newClass("none/h$k"), - newClass("none/h$k$l"), - newClass("none/m"), - newClass("none/m$n"), - newClass("none/m$n$o"), - newClass("none/m$p"), - newClass("none/m$p$q"), - newClass("none/m$p$q$r"), - newClass("none/m$p$q$s") + newClass("none/h$a"), + newClass("none/h$a$a"), + newClass("none/h$b"), + newClass("none/h$b$a"), + newClass("none/h$b$a$a"), + newClass("none/h$b$a$b"), + newClass("none/i"), + newClass("none/i$a"), + newClass("none/i$b") )); } @@ -60,20 +63,23 @@ public class TestDeobfed { deobfuscator.getSourceTree("none/b"); deobfuscator.getSourceTree("none/c"); deobfuscator.getSourceTree("none/d"); - deobfuscator.getSourceTree("none/d$e"); + deobfuscator.getSourceTree("none/d$1"); + deobfuscator.getSourceTree("none/e"); deobfuscator.getSourceTree("none/f"); deobfuscator.getSourceTree("none/g"); + deobfuscator.getSourceTree("none/g$a"); + deobfuscator.getSourceTree("none/g$a$a"); + deobfuscator.getSourceTree("none/g$b"); + deobfuscator.getSourceTree("none/g$b$a"); deobfuscator.getSourceTree("none/h"); - deobfuscator.getSourceTree("none/h$i"); - deobfuscator.getSourceTree("none/h$i$j"); - deobfuscator.getSourceTree("none/h$k"); - deobfuscator.getSourceTree("none/h$k$l"); - deobfuscator.getSourceTree("none/m"); - deobfuscator.getSourceTree("none/m$n"); - deobfuscator.getSourceTree("none/m$n$o"); - deobfuscator.getSourceTree("none/m$p"); - deobfuscator.getSourceTree("none/m$p$q"); - deobfuscator.getSourceTree("none/m$p$q$r"); - deobfuscator.getSourceTree("none/m$p$q$s"); + deobfuscator.getSourceTree("none/h$a"); + deobfuscator.getSourceTree("none/h$a$a"); + deobfuscator.getSourceTree("none/h$b"); + deobfuscator.getSourceTree("none/h$b$a"); + deobfuscator.getSourceTree("none/h$b$a$a"); + deobfuscator.getSourceTree("none/h$b$a$b"); + deobfuscator.getSourceTree("none/i"); + deobfuscator.getSourceTree("none/i$a"); + deobfuscator.getSourceTree("none/i$b"); } } diff --git a/test/cuchaz/enigma/TestInnerClasses.java b/test/cuchaz/enigma/TestInnerClasses.java index 2eb5accc..014a4613 100644 --- a/test/cuchaz/enigma/TestInnerClasses.java +++ b/test/cuchaz/enigma/TestInnerClasses.java @@ -29,19 +29,19 @@ public class TestInnerClasses { private Deobfuscator m_deobfuscator; private static final ClassEntry AnonymousOuter = newClass("none/a"); - private static final ClassEntry AnonymousInner = newClass("none/b"); - private static final ClassEntry SimpleOuter = newClass("none/g"); - private static final ClassEntry SimpleInner = newClass("none/h"); - private static final ClassEntry ConstructorArgsOuter = newClass("none/e"); - private static final ClassEntry ConstructorArgsInner = newClass("none/f"); - private static final ClassEntry AnonymousWithScopeArgsOuter = newClass("none/c"); - private static final ClassEntry AnonymousWithScopeArgsInner = newClass("none/d"); - private static final ClassEntry AnonymousWithOuterAccessOuter = newClass("none/i"); - private static final ClassEntry AnonymousWithOuterAccessInner = newClass("none/j"); - private static final ClassEntry ClassTreeRoot = newClass("none/k"); - private static final ClassEntry ClassTreeLevel1 = newClass("none/l"); - private static final ClassEntry ClassTreeLevel2 = newClass("none/m"); - private static final ClassEntry ClassTreeLevel3 = newClass("none/n"); + private static final ClassEntry AnonymousInner = newClass("none/a$1"); + private static final ClassEntry SimpleOuter = newClass("none/d"); + private static final ClassEntry SimpleInner = newClass("none/d$a"); + private static final ClassEntry ConstructorArgsOuter = newClass("none/c"); + private static final ClassEntry ConstructorArgsInner = newClass("none/c$a"); + private static final ClassEntry AnonymousWithScopeArgsOuter = newClass("none/b"); + private static final ClassEntry AnonymousWithScopeArgsInner = newClass("none/b$1"); + private static final ClassEntry AnonymousWithOuterAccessOuter = newClass("none/e"); + private static final ClassEntry AnonymousWithOuterAccessInner = newClass("none/e$1"); + private static final ClassEntry ClassTreeRoot = newClass("none/f"); + private static final ClassEntry ClassTreeLevel1 = newClass("none/f$a"); + private static final ClassEntry ClassTreeLevel2 = newClass("none/f$a$a"); + private static final ClassEntry ClassTreeLevel3 = newClass("none/f$a$a$a"); public TestInnerClasses() throws Exception { @@ -101,7 +101,7 @@ public class TestInnerClasses { // level 1 ClassEntry fullClassEntry = new ClassEntry(ClassTreeRoot.getName() - + "$" + ClassTreeLevel1.getSimpleName() + + "$" + ClassTreeLevel1.getInnermostClassName() ); assertThat(m_index.containsObfClass(fullClassEntry), is(true)); assertThat(m_index.getOuterClass(ClassTreeLevel1), is(ClassTreeRoot)); @@ -109,8 +109,8 @@ public class TestInnerClasses { // level 2 fullClassEntry = new ClassEntry(ClassTreeRoot.getName() - + "$" + ClassTreeLevel1.getSimpleName() - + "$" + ClassTreeLevel2.getSimpleName() + + "$" + ClassTreeLevel1.getInnermostClassName() + + "$" + ClassTreeLevel2.getInnermostClassName() ); assertThat(m_index.containsObfClass(fullClassEntry), is(true)); assertThat(m_index.getOuterClass(ClassTreeLevel2), is(ClassTreeLevel1)); @@ -118,9 +118,9 @@ public class TestInnerClasses { // level 3 fullClassEntry = new ClassEntry(ClassTreeRoot.getName() - + "$" + ClassTreeLevel1.getSimpleName() - + "$" + ClassTreeLevel2.getSimpleName() - + "$" + ClassTreeLevel3.getSimpleName() + + "$" + ClassTreeLevel1.getInnermostClassName() + + "$" + ClassTreeLevel2.getInnermostClassName() + + "$" + ClassTreeLevel3.getInnermostClassName() ); assertThat(m_index.containsObfClass(fullClassEntry), is(true)); assertThat(m_index.getOuterClass(ClassTreeLevel3), is(ClassTreeLevel2)); diff --git a/test/cuchaz/enigma/TestSourceIndex.java b/test/cuchaz/enigma/TestSourceIndex.java index 94bf941d..13971249 100644 --- a/test/cuchaz/enigma/TestSourceIndex.java +++ b/test/cuchaz/enigma/TestSourceIndex.java @@ -24,7 +24,7 @@ import cuchaz.enigma.mapping.ClassEntry; public class TestSourceIndex { - @Test + // TEMP @Test public void indexEverything() throws Exception { diff --git a/test/cuchaz/enigma/TestTranslator.java b/test/cuchaz/enigma/TestTranslator.java index 02526050..45c69bb2 100644 --- a/test/cuchaz/enigma/TestTranslator.java +++ b/test/cuchaz/enigma/TestTranslator.java @@ -101,26 +101,31 @@ public class TestTranslator { public void innerClasses() { // classes - assertMapping(newClass("none/h"), newClass("deobf/H_OuterClass")); - assertMapping(newClass("none/h$i"), newClass("deobf/H_OuterClass$I_InnerClass")); - assertMapping(newClass("none/h$i$j"), newClass("deobf/H_OuterClass$I_InnerClass$J_InnerInnerClass")); - assertMapping(newClass("none/h$k"), newClass("deobf/H_OuterClass$k")); - assertMapping(newClass("none/h$k$l"), newClass("deobf/H_OuterClass$k$L_NamedInnerClass")); + assertMapping(newClass("none/g"), newClass("deobf/G_OuterClass")); + assertMapping(newClass("none/g$a"), newClass("deobf/G_OuterClass$A_InnerClass")); + assertMapping(newClass("none/g$a$a"), newClass("deobf/G_OuterClass$A_InnerClass$A_InnerInnerClass")); + assertMapping(newClass("none/g$b"), newClass("deobf/G_OuterClass$b")); + assertMapping(newClass("none/g$b$a"), newClass("deobf/G_OuterClass$b$A_NamedInnerClass")); // fields - assertMapping(newField("none/h$i", "a", "I"), newField("deobf/H_OuterClass$I_InnerClass", "f1", "I")); - assertMapping(newField("none/h$i", "a", "Ljava/lang/String;"), newField("deobf/H_OuterClass$I_InnerClass", "f2", "Ljava/lang/String;")); - assertMapping(newField("none/h$i$j", "a", "I"), newField("deobf/H_OuterClass$I_InnerClass$J_InnerInnerClass", "f3", "I")); - assertMapping(newField("none/h$k$l", "a", "I"), newField("deobf/H_OuterClass$k$L_NamedInnerClass", "f4", "I")); + assertMapping(newField("none/g$a", "a", "I"), newField("deobf/G_OuterClass$A_InnerClass", "f1", "I")); + assertMapping(newField("none/g$a", "a", "Ljava/lang/String;"), newField("deobf/G_OuterClass$A_InnerClass", "f2", "Ljava/lang/String;")); + assertMapping(newField("none/g$a$a", "a", "I"), newField("deobf/G_OuterClass$A_InnerClass$A_InnerInnerClass", "f3", "I")); + assertMapping(newField("none/g$b$a", "a", "I"), newField("deobf/G_OuterClass$b$A_NamedInnerClass", "f4", "I")); // methods - assertMapping(newMethod("none/h$i", "a", "()V"), newMethod("deobf/H_OuterClass$I_InnerClass", "m1", "()V")); - assertMapping(newMethod("none/h$i$j", "a", "()V"), newMethod("deobf/H_OuterClass$I_InnerClass$J_InnerInnerClass", "m2", "()V")); + assertMapping(newMethod("none/g$a", "a", "()V"), newMethod("deobf/G_OuterClass$A_InnerClass", "m1", "()V")); + assertMapping(newMethod("none/g$a$a", "a", "()V"), newMethod("deobf/G_OuterClass$A_InnerClass$A_InnerInnerClass", "m2", "()V")); } @Test public void namelessClass() { - assertMapping(newClass("none/m"), newClass("none/m")); + assertMapping(newClass("none/h"), newClass("none/h")); + } + + @Test + public void testGenerics() { + // TODO } private void assertMapping(Entry obf, Entry deobf) { 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 00000000..4e091797 --- /dev/null +++ b/test/cuchaz/enigma/inputs/translation/F_ObjectMethods.java @@ -0,0 +1,19 @@ +package cuchaz.enigma.inputs.translation; + +public class F_ObjectMethods { + + public void callEmAll() + throws Throwable { + clone(); + equals(this); + finalize(); + getClass(); + hashCode(); + notify(); + notifyAll(); + toString(); + wait(); + wait(0); + wait(0, 0); + } +} diff --git a/test/cuchaz/enigma/inputs/translation/G_ObjectMethods.java b/test/cuchaz/enigma/inputs/translation/G_ObjectMethods.java deleted file mode 100644 index ebad5a38..00000000 --- a/test/cuchaz/enigma/inputs/translation/G_ObjectMethods.java +++ /dev/null @@ -1,19 +0,0 @@ -package cuchaz.enigma.inputs.translation; - -public class G_ObjectMethods { - - public void callEmAll() - throws Throwable { - clone(); - equals(this); - finalize(); - getClass(); - hashCode(); - notify(); - notifyAll(); - toString(); - wait(); - wait(0); - wait(0, 0); - } -} 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 00000000..0856afed --- /dev/null +++ b/test/cuchaz/enigma/inputs/translation/G_OuterClass.java @@ -0,0 +1,26 @@ +package cuchaz.enigma.inputs.translation; + + +public class G_OuterClass { + + public class A_InnerClass { + + public int f1; + public String f2; + + public void m1() {} + + public class A_InnerInnerClass { + + public int f3; + + public void m2() {} + } + } + + public class B_NamelessClass { + public class A_NamedInnerClass { + public int f4; + } + } +} 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 00000000..5802d789 --- /dev/null +++ b/test/cuchaz/enigma/inputs/translation/H_NamelessClass.java @@ -0,0 +1,28 @@ +package cuchaz.enigma.inputs.translation; + + +public class H_NamelessClass { + + public class A_InnerClass { + + public int f1; + public String f2; + + public void m1() {} + + public class A_InnerInnerClass { + + public int f3; + + public void m2() {} + } + } + + public class B_NamelessClass { + public class A_NamedInnerClass { + public int f4; + public class A_AnotherInnerClass {} + public class B_YetAnotherInnerClass {} + } + } +} diff --git a/test/cuchaz/enigma/inputs/translation/H_OuterClass.java b/test/cuchaz/enigma/inputs/translation/H_OuterClass.java deleted file mode 100644 index 995c65d2..00000000 --- a/test/cuchaz/enigma/inputs/translation/H_OuterClass.java +++ /dev/null @@ -1,26 +0,0 @@ -package cuchaz.enigma.inputs.translation; - - -public class H_OuterClass { - - public class I_InnerClass { - - public int f1; - public String f2; - - public void m1() {} - - public class J_InnerInnerClass { - - public int f3; - - public void m2() {} - } - } - - public class K_NamelessClass { - public class L_NamedInnerClass { - public int f4; - } - } -} 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 00000000..191931a8 --- /dev/null +++ b/test/cuchaz/enigma/inputs/translation/I_Generics.java @@ -0,0 +1,25 @@ +package cuchaz.enigma.inputs.translation; + +import java.util.List; +import java.util.Map; + + +public class I_Generics { + + public class A_Type { + } + + public List f1; + public List f2; + public Map f3; + + public class B_Generic { + public T f4; + public T m1() { + return null; + } + } + + public B_Generic f5; + public B_Generic f6; +} diff --git a/test/cuchaz/enigma/inputs/translation/M_NamelessClass.java b/test/cuchaz/enigma/inputs/translation/M_NamelessClass.java deleted file mode 100644 index 5d8acbc7..00000000 --- a/test/cuchaz/enigma/inputs/translation/M_NamelessClass.java +++ /dev/null @@ -1,28 +0,0 @@ -package cuchaz.enigma.inputs.translation; - - -public class M_NamelessClass { - - public class N_InnerClass { - - public int f1; - public String f2; - - public void m1() {} - - public class O_InnerInnerClass { - - public int f3; - - public void m2() {} - } - } - - public class P_NamelessClass { - public class Q_NamedInnerClass { - public int f4; - public class R_AnotherInnerClass {} - public class S_YetAnotherInnerClass {} - } - } -} diff --git a/test/cuchaz/enigma/resources/translation.mappings b/test/cuchaz/enigma/resources/translation.mappings index 5dffaf1d..55bd7e5c 100644 --- a/test/cuchaz/enigma/resources/translation.mappings +++ b/test/cuchaz/enigma/resources/translation.mappings @@ -17,15 +17,16 @@ CLASS none/c deobf/C_SubClass FIELD c f4 I METHOD a m1 ()I METHOD c m3 ()I -CLASS none/h deobf/H_OuterClass - CLASS none/i I_InnerClass - CLASS none/j J_InnerInnerClass +CLASS none/g deobf/G_OuterClass + CLASS none/g$a A_InnerClass + CLASS none/g$a$a A_InnerInnerClass FIELD a f3 I METHOD a m2 ()V FIELD a f1 I FIELD a f2 Ljava/lang/String; METHOD a m1 ()V - CLASS none/k - CLASS none/l L_NamedInnerClass + CLASS none/g$b + CLASS none/g$b$a A_NamedInnerClass FIELD a f4 I -CLASS none/m \ No newline at end of file +CLASS none/h +CLASS none/i I_Generics -- cgit v1.2.3 From 5e3743a0aca3529eacf9be400c8b8d7547f66e7f Mon Sep 17 00:00:00 2001 From: jeff Date: Mon, 16 Mar 2015 19:22:22 -0400 Subject: started adding minimal support for generics fixed mark-as-deobfuscated issue --- test/cuchaz/enigma/TestSourceIndex.java | 2 +- test/cuchaz/enigma/TestTranslator.java | 17 ++- test/cuchaz/enigma/TestType.java | 163 +++++++++++++++++++++- test/cuchaz/enigma/resources/translation.mappings | 11 +- 4 files changed, 184 insertions(+), 9 deletions(-) (limited to 'test') diff --git a/test/cuchaz/enigma/TestSourceIndex.java b/test/cuchaz/enigma/TestSourceIndex.java index 13971249..94bf941d 100644 --- a/test/cuchaz/enigma/TestSourceIndex.java +++ b/test/cuchaz/enigma/TestSourceIndex.java @@ -24,7 +24,7 @@ import cuchaz.enigma.mapping.ClassEntry; public class TestSourceIndex { - // TEMP @Test + @Test public void indexEverything() throws Exception { diff --git a/test/cuchaz/enigma/TestTranslator.java b/test/cuchaz/enigma/TestTranslator.java index 45c69bb2..1b617405 100644 --- a/test/cuchaz/enigma/TestTranslator.java +++ b/test/cuchaz/enigma/TestTranslator.java @@ -125,7 +125,22 @@ public class TestTranslator { @Test public void testGenerics() { - // TODO + + // classes + assertMapping(newClass("none/i"), newClass("deobf/I_Generics")); + assertMapping(newClass("none/i$a"), newClass("deobf/I_Generics$A_Type")); + assertMapping(newClass("none/i$b"), newClass("deobf/I_Generics$B_Generic")); + + // fields + assertMapping(newField("none/i", "a", "Ljava/util/List;"), newField("deobf/I_Generics", "f1", "Ljava/util/List;")); + assertMapping(newField("none/i", "b", "Ljava/util/List;"), newField("deobf/I_Generics", "f2", "Ljava/util/List;")); + assertMapping(newField("none/i", "a", "Ljava/util/Map;"), newField("deobf/I_Generics", "f3", "Ljava/util/Map;")); + assertMapping(newField("none/i$b", "a", "Ljava/lang/Object;"), newField("deobf/I_Generics$B_Generic", "f4", "Ljava/lang/Object;")); + assertMapping(newField("none/i", "a", "Lnone/i$b;"), newField("deobf/I_Generics", "f5", "Ldeobf/I_Generics$B_Generic;")); + assertMapping(newField("none/i", "b", "Lnone/i$b;"), newField("deobf/I_Generics", "f6", "Ldeobf/I_Generics$B_Generic;")); + + // methods + assertMapping(newMethod("none/i$b", "a", "()Ljava/lang/Object;"), newMethod("deobf/I_Generics$B_Generic", "m1", "()Ljava/lang/Object;")); } private void assertMapping(Entry obf, Entry deobf) { diff --git a/test/cuchaz/enigma/TestType.java b/test/cuchaz/enigma/TestType.java index 93f864b0..544a10c1 100644 --- a/test/cuchaz/enigma/TestType.java +++ b/test/cuchaz/enigma/TestType.java @@ -1,13 +1,13 @@ package cuchaz.enigma; -import org.junit.Test; - +import static cuchaz.enigma.TestEntryFactory.*; import static org.hamcrest.MatcherAssert.*; import static org.hamcrest.Matchers.*; -import cuchaz.enigma.mapping.Type; +import org.junit.Test; -import static cuchaz.enigma.TestEntryFactory.*; +import cuchaz.enigma.mapping.ParameterizedType; +import cuchaz.enigma.mapping.Type; public class TestType { @@ -24,6 +24,7 @@ public class TestType { assertThat(new Type("D").isVoid(), is(false)); assertThat(new Type("LFoo;").isVoid(), is(false)); assertThat(new Type("[I").isVoid(), is(false)); + assertThat(new Type("TFoo;").isVoid(), is(false)); } @Test @@ -38,6 +39,7 @@ public class TestType { assertThat(new Type("D").isPrimitive(), is(true)); assertThat(new Type("LFoo;").isPrimitive(), is(false)); assertThat(new Type("[I").isPrimitive(), is(false)); + assertThat(new Type("TFoo;").isPrimitive(), is(false)); } @Test @@ -62,13 +64,20 @@ public class TestType { assertThat(new Type("F").isClass(), is(false)); assertThat(new Type("D").isClass(), is(false)); assertThat(new Type("LFoo;").isClass(), is(true)); + assertThat(new Type("LFoo;").isClass(), is(true)); + assertThat(new Type("LFoo;").isClass(), is(true)); + assertThat(new Type("LFoo;>;").isClass(), is(true)); assertThat(new Type("[I").isClass(), is(false)); + assertThat(new Type("TFoo;").isClass(), is(false)); } @Test public void getClassEntry() { assertThat(new Type("LFoo;").getClassEntry(), is(newClass("Foo"))); assertThat(new Type("LFoo;").getClassEntry(), is(newClass("Foo"))); + assertThat(new Type("LFoo;").getClassEntry(), is(newClass("Foo"))); + assertThat(new Type("LFoo;").getClassEntry(), is(newClass("Foo"))); + assertThat(new Type("LFoo;>;").getClassEntry(), is(newClass("Foo"))); } @Test @@ -89,6 +98,7 @@ public class TestType { assertThat(new Type("D").isArray(), is(false)); assertThat(new Type("LFoo;").isArray(), is(false)); assertThat(new Type("[I").isArray(), is(true)); + assertThat(new Type("TFoo;").isArray(), is(false)); } @Test @@ -106,6 +116,30 @@ public class TestType { assertThat(new Type("[Ljava/lang/String;").getArrayType(), is(new Type("Ljava/lang/String;"))); } + @Test + public void isTemplate() { + assertThat(new Type("V").isTemplate(), is(false)); + assertThat(new Type("Z").isTemplate(), is(false)); + assertThat(new Type("B").isTemplate(), is(false)); + assertThat(new Type("C").isTemplate(), is(false)); + assertThat(new Type("I").isTemplate(), is(false)); + assertThat(new Type("J").isTemplate(), is(false)); + assertThat(new Type("F").isTemplate(), is(false)); + assertThat(new Type("D").isTemplate(), is(false)); + assertThat(new Type("LFoo;").isTemplate(), is(false)); + assertThat(new Type("LFoo;").isTemplate(), is(false)); + assertThat(new Type("LFoo;").isTemplate(), is(false)); + assertThat(new Type("LFoo;>;").isTemplate(), is(false)); + assertThat(new Type("[I").isTemplate(), is(false)); + assertThat(new Type("TFoo;").isTemplate(), is(true)); + } + + @Test + public void getTemplate() { + assertThat(new Type("TT;").getTemplate(), is("T")); + assertThat(new Type("TFoo;").getTemplate(), is("Foo")); + } + @Test public void hasClass() { assertThat(new Type("LFoo;").hasClass(), is(true)); @@ -117,6 +151,37 @@ public class TestType { assertThat(new Type("[I").hasClass(), is(false)); assertThat(new Type("[[[I").hasClass(), is(false)); assertThat(new Type("Z").hasClass(), is(false)); + assertThat(new Type("TFoo;").hasClass(), is(false)); + } + + @Test + public void parameters() { + assertThat(new Type("LFoo;").parameters(), contains( + new Type("I") + )); + assertThat(new Type("LFoo;").parameters(), contains( + new Type("I"), + new Type("I"), + new Type("I"), + new Type("I") + )); + assertThat(new Type("LFoo;").parameters(), contains( + new Type("LBar;") + )); + assertThat(new Type("LFoo;").parameters(), contains( + new Type("LBar;"), + new Type("LCow;"), + new Type("LCheese;") + )); + + assertThat(new Type("LFoo;>;").parameters(), contains( + new Type("LBar;") + )); + + assertThat(new Type("LFoo;>;").parameters().iterator().next().parameters(), contains( + new Type("LCow;"), + new Type("LCheese;") + )); } @Test @@ -171,7 +236,18 @@ public class TestType { assertThat(Type.parseFirst("LFoo;[LFoo;"), is(answer)); } } - + + @Test + public void parseTemplate() { + final String answer = "TFoo;"; + assertThat(Type.parseFirst("TFoo;"), is(answer)); + assertThat(Type.parseFirst("TFoo;I"), is(answer)); + assertThat(Type.parseFirst("TFoo;JZ"), is(answer)); + assertThat(Type.parseFirst("TFoo;[I"), is(answer)); + assertThat(Type.parseFirst("TFoo;LFoo;"), is(answer)); + assertThat(Type.parseFirst("TFoo;[LFoo;"), is(answer)); + } + @Test public void parseArray() { { @@ -215,15 +291,90 @@ public class TestType { assertThat(new Type("[[[I"), is(new Type("[[[I"))); assertThat(new Type("[LFoo;"), is(new Type("[LFoo;"))); assertThat(new Type("LFoo;"), is(new Type("LFoo;"))); + assertThat(new Type("LFoo;"), is(new Type("LFoo;"))); + assertThat(new Type("TFoo;"), is(new Type("TFoo;"))); assertThat(new Type("V"), is(not(new Type("I")))); assertThat(new Type("I"), is(not(new Type("J")))); assertThat(new Type("I"), is(not(new Type("LBar;")))); assertThat(new Type("I"), is(not(new Type("[I")))); assertThat(new Type("LFoo;"), is(not(new Type("LBar;")))); - assertThat(new Type("LFoo;"), is(not(new Type("LFoo;")))); assertThat(new Type("[I"), is(not(new Type("[Z")))); assertThat(new Type("[[[I"), is(not(new Type("[I")))); assertThat(new Type("[LFoo;"), is(not(new Type("[LBar;")))); + assertThat(new Type("TFoo;"), is(not(new Type("TBar;")))); + } + + @Test + public void testToString() { + assertThat(new Type("V").toString(), is("V")); + assertThat(new Type("Z").toString(), is("Z")); + assertThat(new Type("B").toString(), is("B")); + assertThat(new Type("C").toString(), is("C")); + assertThat(new Type("I").toString(), is("I")); + assertThat(new Type("J").toString(), is("J")); + assertThat(new Type("F").toString(), is("F")); + assertThat(new Type("D").toString(), is("D")); + assertThat(new Type("LFoo;").toString(), is("LFoo;")); + assertThat(new Type("[I").toString(), is("[I")); + assertThat(new Type("[[[I").toString(), is("[[[I")); + assertThat(new Type("[LFoo;").toString(), is("[LFoo;")); + assertThat(new Type("LFoo;").toString(), is("LFoo;")); + assertThat(new Type("LFoo;").toString(), is("LFoo;")); + assertThat(new Type("LFoo;>;").toString(), is("LFoo;")); + assertThat(new Type("TFoo;").toString(), is("TFoo;")); + } + + private ParameterizedType ptype(String name) { + return new ParameterizedType(new Type(name)); + } + + @Test + public void equalsWithParameters() { + assertThat(ptype("V"), is(ptype("V"))); + assertThat(ptype("Z"), is(ptype("Z"))); + assertThat(ptype("B"), is(ptype("B"))); + assertThat(ptype("C"), is(ptype("C"))); + assertThat(ptype("I"), is(ptype("I"))); + assertThat(ptype("J"), is(ptype("J"))); + assertThat(ptype("F"), is(ptype("F"))); + assertThat(ptype("D"), is(ptype("D"))); + assertThat(ptype("LFoo;"), is(ptype("LFoo;"))); + assertThat(ptype("[I"), is(ptype("[I"))); + assertThat(ptype("[[[I"), is(ptype("[[[I"))); + assertThat(ptype("[LFoo;"), is(ptype("[LFoo;"))); + assertThat(ptype("LFoo;"), is(ptype("LFoo;"))); + assertThat(ptype("TFoo;"), is(ptype("TFoo;"))); + + assertThat(ptype("V"), is(not(ptype("I")))); + assertThat(ptype("I"), is(not(ptype("J")))); + assertThat(ptype("I"), is(not(ptype("LBar;")))); + assertThat(ptype("I"), is(not(ptype("[I")))); + assertThat(ptype("LFoo;"), is(not(ptype("LBar;")))); + assertThat(ptype("[I"), is(not(ptype("[Z")))); + assertThat(ptype("[[[I"), is(not(ptype("[I")))); + assertThat(ptype("[LFoo;"), is(not(ptype("[LBar;")))); + assertThat(ptype("LFoo;"), is(not(ptype("LFoo;")))); + assertThat(ptype("TFoo;"), is(not(ptype("TBar;")))); + } + + @Test + public void testToStringWithParams() { + assertThat(ptype("V").toString(), is("V")); + assertThat(ptype("Z").toString(), is("Z")); + assertThat(ptype("B").toString(), is("B")); + assertThat(ptype("C").toString(), is("C")); + assertThat(ptype("I").toString(), is("I")); + assertThat(ptype("J").toString(), is("J")); + assertThat(ptype("F").toString(), is("F")); + assertThat(ptype("D").toString(), is("D")); + assertThat(ptype("LFoo;").toString(), is("LFoo;")); + assertThat(ptype("[I").toString(), is("[I")); + assertThat(ptype("[[[I").toString(), is("[[[I")); + assertThat(ptype("[LFoo;").toString(), is("[LFoo;")); + assertThat(ptype("LFoo;").toString(), is("LFoo;")); + assertThat(ptype("LFoo;").toString(), is("LFoo;")); + assertThat(ptype("LFoo;>;").toString(), is("LFoo;>;")); + assertThat(ptype("TFoo;").toString(), is("TFoo;")); } } diff --git a/test/cuchaz/enigma/resources/translation.mappings b/test/cuchaz/enigma/resources/translation.mappings index 55bd7e5c..db78c19d 100644 --- a/test/cuchaz/enigma/resources/translation.mappings +++ b/test/cuchaz/enigma/resources/translation.mappings @@ -29,4 +29,13 @@ CLASS none/g deobf/G_OuterClass CLASS none/g$b$a A_NamedInnerClass FIELD a f4 I CLASS none/h -CLASS none/i I_Generics +CLASS none/i deobf/I_Generics + CLASS none/i$a A_Type + CLASS none/i$b B_Generic + FIELD a f4 Ljava/lang/Object; + METHOD a m1 ()Ljava/lang/Object; + FIELD a f1 Ljava/util/List; + FIELD b f2 Ljava/util/List; + FIELD a f3 Ljava/util/Map; + FIELD a f5 Lnone/i$b; + FIELD b f6 Lnone/i$b; -- cgit v1.2.3 From ecfda21f3db9e62e3acf074e9842e92ace4cb3ab Mon Sep 17 00:00:00 2001 From: jeff Date: Tue, 17 Mar 2015 20:01:55 -0400 Subject: parsing generic signatures is tricky. don't write custom code to do it. switching to library instead --- test/cuchaz/enigma/TestType.java | 167 +++------------------------------------ 1 file changed, 10 insertions(+), 157 deletions(-) (limited to 'test') diff --git a/test/cuchaz/enigma/TestType.java b/test/cuchaz/enigma/TestType.java index 544a10c1..71aaaee2 100644 --- a/test/cuchaz/enigma/TestType.java +++ b/test/cuchaz/enigma/TestType.java @@ -6,7 +6,6 @@ import static org.hamcrest.Matchers.*; import org.junit.Test; -import cuchaz.enigma.mapping.ParameterizedType; import cuchaz.enigma.mapping.Type; @@ -24,7 +23,6 @@ public class TestType { assertThat(new Type("D").isVoid(), is(false)); assertThat(new Type("LFoo;").isVoid(), is(false)); assertThat(new Type("[I").isVoid(), is(false)); - assertThat(new Type("TFoo;").isVoid(), is(false)); } @Test @@ -39,7 +37,6 @@ public class TestType { assertThat(new Type("D").isPrimitive(), is(true)); assertThat(new Type("LFoo;").isPrimitive(), is(false)); assertThat(new Type("[I").isPrimitive(), is(false)); - assertThat(new Type("TFoo;").isPrimitive(), is(false)); } @Test @@ -64,26 +61,19 @@ public class TestType { assertThat(new Type("F").isClass(), is(false)); assertThat(new Type("D").isClass(), is(false)); assertThat(new Type("LFoo;").isClass(), is(true)); - assertThat(new Type("LFoo;").isClass(), is(true)); - assertThat(new Type("LFoo;").isClass(), is(true)); - assertThat(new Type("LFoo;>;").isClass(), is(true)); assertThat(new Type("[I").isClass(), is(false)); - assertThat(new Type("TFoo;").isClass(), is(false)); } @Test public void getClassEntry() { assertThat(new Type("LFoo;").getClassEntry(), is(newClass("Foo"))); - assertThat(new Type("LFoo;").getClassEntry(), is(newClass("Foo"))); - assertThat(new Type("LFoo;").getClassEntry(), is(newClass("Foo"))); - assertThat(new Type("LFoo;").getClassEntry(), is(newClass("Foo"))); - assertThat(new Type("LFoo;>;").getClassEntry(), is(newClass("Foo"))); + assertThat(new Type("Ljava/lang/String;").getClassEntry(), is(newClass("java/lang/String"))); } @Test public void getArrayClassEntry() { assertThat(new Type("[LFoo;").getClassEntry(), is(newClass("Foo"))); - assertThat(new Type("[[[LFoo;").getClassEntry(), is(newClass("Foo"))); + assertThat(new Type("[[[Ljava/lang/String;").getClassEntry(), is(newClass("java/lang/String"))); } @Test @@ -98,7 +88,6 @@ public class TestType { assertThat(new Type("D").isArray(), is(false)); assertThat(new Type("LFoo;").isArray(), is(false)); assertThat(new Type("[I").isArray(), is(true)); - assertThat(new Type("TFoo;").isArray(), is(false)); } @Test @@ -116,34 +105,10 @@ public class TestType { assertThat(new Type("[Ljava/lang/String;").getArrayType(), is(new Type("Ljava/lang/String;"))); } - @Test - public void isTemplate() { - assertThat(new Type("V").isTemplate(), is(false)); - assertThat(new Type("Z").isTemplate(), is(false)); - assertThat(new Type("B").isTemplate(), is(false)); - assertThat(new Type("C").isTemplate(), is(false)); - assertThat(new Type("I").isTemplate(), is(false)); - assertThat(new Type("J").isTemplate(), is(false)); - assertThat(new Type("F").isTemplate(), is(false)); - assertThat(new Type("D").isTemplate(), is(false)); - assertThat(new Type("LFoo;").isTemplate(), is(false)); - assertThat(new Type("LFoo;").isTemplate(), is(false)); - assertThat(new Type("LFoo;").isTemplate(), is(false)); - assertThat(new Type("LFoo;>;").isTemplate(), is(false)); - assertThat(new Type("[I").isTemplate(), is(false)); - assertThat(new Type("TFoo;").isTemplate(), is(true)); - } - - @Test - public void getTemplate() { - assertThat(new Type("TT;").getTemplate(), is("T")); - assertThat(new Type("TFoo;").getTemplate(), is("Foo")); - } - @Test public void hasClass() { assertThat(new Type("LFoo;").hasClass(), is(true)); - assertThat(new Type("LCow;").hasClass(), is(true)); + assertThat(new Type("Ljava/lang/String;").hasClass(), is(true)); assertThat(new Type("[LBar;").hasClass(), is(true)); assertThat(new Type("[[[LCat;").hasClass(), is(true)); @@ -151,37 +116,6 @@ public class TestType { assertThat(new Type("[I").hasClass(), is(false)); assertThat(new Type("[[[I").hasClass(), is(false)); assertThat(new Type("Z").hasClass(), is(false)); - assertThat(new Type("TFoo;").hasClass(), is(false)); - } - - @Test - public void parameters() { - assertThat(new Type("LFoo;").parameters(), contains( - new Type("I") - )); - assertThat(new Type("LFoo;").parameters(), contains( - new Type("I"), - new Type("I"), - new Type("I"), - new Type("I") - )); - assertThat(new Type("LFoo;").parameters(), contains( - new Type("LBar;") - )); - assertThat(new Type("LFoo;").parameters(), contains( - new Type("LBar;"), - new Type("LCow;"), - new Type("LCheese;") - )); - - assertThat(new Type("LFoo;>;").parameters(), contains( - new Type("LBar;") - )); - - assertThat(new Type("LFoo;>;").parameters().iterator().next().parameters(), contains( - new Type("LCow;"), - new Type("LCheese;") - )); } @Test @@ -218,36 +152,16 @@ public class TestType { assertThat(Type.parseFirst("LFoo;[LFoo;"), is(answer)); } { - final String answer = "LFoo;"; - assertThat(Type.parseFirst("LFoo;"), is(answer)); - assertThat(Type.parseFirst("LFoo;I"), is(answer)); - assertThat(Type.parseFirst("LFoo;JZ"), is(answer)); - assertThat(Type.parseFirst("LFoo;[I"), is(answer)); - assertThat(Type.parseFirst("LFoo;LFoo;"), is(answer)); - assertThat(Type.parseFirst("LFoo;[LFoo;"), is(answer)); - } - { - final String answer = "LFoo;"; - assertThat(Type.parseFirst("LFoo;"), is(answer)); - assertThat(Type.parseFirst("LFoo;I"), is(answer)); - assertThat(Type.parseFirst("LFoo;JZ"), is(answer)); - assertThat(Type.parseFirst("LFoo;[I"), is(answer)); - assertThat(Type.parseFirst("LFoo;LFoo;"), is(answer)); - assertThat(Type.parseFirst("LFoo;[LFoo;"), is(answer)); + final String answer = "Ljava/lang/String;"; + assertThat(Type.parseFirst("Ljava/lang/String;"), is(answer)); + assertThat(Type.parseFirst("Ljava/lang/String;I"), is(answer)); + assertThat(Type.parseFirst("Ljava/lang/String;JZ"), is(answer)); + assertThat(Type.parseFirst("Ljava/lang/String;[I"), is(answer)); + assertThat(Type.parseFirst("Ljava/lang/String;LFoo;"), is(answer)); + assertThat(Type.parseFirst("Ljava/lang/String;[LFoo;"), is(answer)); } } - @Test - public void parseTemplate() { - final String answer = "TFoo;"; - assertThat(Type.parseFirst("TFoo;"), is(answer)); - assertThat(Type.parseFirst("TFoo;I"), is(answer)); - assertThat(Type.parseFirst("TFoo;JZ"), is(answer)); - assertThat(Type.parseFirst("TFoo;[I"), is(answer)); - assertThat(Type.parseFirst("TFoo;LFoo;"), is(answer)); - assertThat(Type.parseFirst("TFoo;[LFoo;"), is(answer)); - } - @Test public void parseArray() { { @@ -290,9 +204,6 @@ public class TestType { assertThat(new Type("[I"), is(new Type("[I"))); assertThat(new Type("[[[I"), is(new Type("[[[I"))); assertThat(new Type("[LFoo;"), is(new Type("[LFoo;"))); - assertThat(new Type("LFoo;"), is(new Type("LFoo;"))); - assertThat(new Type("LFoo;"), is(new Type("LFoo;"))); - assertThat(new Type("TFoo;"), is(new Type("TFoo;"))); assertThat(new Type("V"), is(not(new Type("I")))); assertThat(new Type("I"), is(not(new Type("J")))); @@ -302,7 +213,6 @@ public class TestType { assertThat(new Type("[I"), is(not(new Type("[Z")))); assertThat(new Type("[[[I"), is(not(new Type("[I")))); assertThat(new Type("[LFoo;"), is(not(new Type("[LBar;")))); - assertThat(new Type("TFoo;"), is(not(new Type("TBar;")))); } @Test @@ -319,62 +229,5 @@ public class TestType { assertThat(new Type("[I").toString(), is("[I")); assertThat(new Type("[[[I").toString(), is("[[[I")); assertThat(new Type("[LFoo;").toString(), is("[LFoo;")); - assertThat(new Type("LFoo;").toString(), is("LFoo;")); - assertThat(new Type("LFoo;").toString(), is("LFoo;")); - assertThat(new Type("LFoo;>;").toString(), is("LFoo;")); - assertThat(new Type("TFoo;").toString(), is("TFoo;")); - } - - private ParameterizedType ptype(String name) { - return new ParameterizedType(new Type(name)); - } - - @Test - public void equalsWithParameters() { - assertThat(ptype("V"), is(ptype("V"))); - assertThat(ptype("Z"), is(ptype("Z"))); - assertThat(ptype("B"), is(ptype("B"))); - assertThat(ptype("C"), is(ptype("C"))); - assertThat(ptype("I"), is(ptype("I"))); - assertThat(ptype("J"), is(ptype("J"))); - assertThat(ptype("F"), is(ptype("F"))); - assertThat(ptype("D"), is(ptype("D"))); - assertThat(ptype("LFoo;"), is(ptype("LFoo;"))); - assertThat(ptype("[I"), is(ptype("[I"))); - assertThat(ptype("[[[I"), is(ptype("[[[I"))); - assertThat(ptype("[LFoo;"), is(ptype("[LFoo;"))); - assertThat(ptype("LFoo;"), is(ptype("LFoo;"))); - assertThat(ptype("TFoo;"), is(ptype("TFoo;"))); - - assertThat(ptype("V"), is(not(ptype("I")))); - assertThat(ptype("I"), is(not(ptype("J")))); - assertThat(ptype("I"), is(not(ptype("LBar;")))); - assertThat(ptype("I"), is(not(ptype("[I")))); - assertThat(ptype("LFoo;"), is(not(ptype("LBar;")))); - assertThat(ptype("[I"), is(not(ptype("[Z")))); - assertThat(ptype("[[[I"), is(not(ptype("[I")))); - assertThat(ptype("[LFoo;"), is(not(ptype("[LBar;")))); - assertThat(ptype("LFoo;"), is(not(ptype("LFoo;")))); - assertThat(ptype("TFoo;"), is(not(ptype("TBar;")))); - } - - @Test - public void testToStringWithParams() { - assertThat(ptype("V").toString(), is("V")); - assertThat(ptype("Z").toString(), is("Z")); - assertThat(ptype("B").toString(), is("B")); - assertThat(ptype("C").toString(), is("C")); - assertThat(ptype("I").toString(), is("I")); - assertThat(ptype("J").toString(), is("J")); - assertThat(ptype("F").toString(), is("F")); - assertThat(ptype("D").toString(), is("D")); - assertThat(ptype("LFoo;").toString(), is("LFoo;")); - assertThat(ptype("[I").toString(), is("[I")); - assertThat(ptype("[[[I").toString(), is("[[[I")); - assertThat(ptype("[LFoo;").toString(), is("[LFoo;")); - assertThat(ptype("LFoo;").toString(), is("LFoo;")); - assertThat(ptype("LFoo;").toString(), is("LFoo;")); - assertThat(ptype("LFoo;>;").toString(), is("LFoo;>;")); - assertThat(ptype("TFoo;").toString(), is("TFoo;")); } } -- cgit v1.2.3 From 966011eda8f20e591708e687be7207c2defa6b70 Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 18 Mar 2015 22:00:50 -0400 Subject: fix broken test we're not implementing generic parsing anymore --- test/cuchaz/enigma/TestSignature.java | 8 -------- 1 file changed, 8 deletions(-) (limited to 'test') diff --git a/test/cuchaz/enigma/TestSignature.java b/test/cuchaz/enigma/TestSignature.java index 183a4fd4..649b76dd 100644 --- a/test/cuchaz/enigma/TestSignature.java +++ b/test/cuchaz/enigma/TestSignature.java @@ -71,14 +71,6 @@ public class TestSignature { )); assertThat(sig.getReturnType(), is(new Type("LBar;"))); } - { - final Signature sig = new Signature("(LFoo;LMoo;)LBar;"); - assertThat(sig.getArgumentTypes(), contains( - new Type("LFoo;"), - new Type("LMoo;") - )); - assertThat(sig.getReturnType(), is(new Type("LBar;"))); - } } @Test -- cgit v1.2.3 From 51b92b780b57cc955e0618d09fbc3aa95ff47163 Mon Sep 17 00:00:00 2001 From: Cuchaz Date: Sun, 19 Apr 2015 18:51:04 -0400 Subject: relicense Enigma as LGPL --- test/cuchaz/enigma/TestDeobfed.java | 10 ++++++++++ test/cuchaz/enigma/TestDeobfuscator.java | 9 ++++----- test/cuchaz/enigma/TestEntryFactory.java | 9 ++++----- test/cuchaz/enigma/TestInnerClasses.java | 9 ++++----- test/cuchaz/enigma/TestJarIndexConstructorReferences.java | 8 ++++---- test/cuchaz/enigma/TestJarIndexInheritanceTree.java | 8 ++++---- test/cuchaz/enigma/TestJarIndexLoneClass.java | 9 ++++----- test/cuchaz/enigma/TestSignature.java | 10 ++++++++++ test/cuchaz/enigma/TestSourceIndex.java | 9 ++++----- test/cuchaz/enigma/TestTokensConstructors.java | 8 ++++---- test/cuchaz/enigma/TestTranslator.java | 10 ++++++++++ test/cuchaz/enigma/TestType.java | 10 ++++++++++ test/cuchaz/enigma/TokenChecker.java | 8 ++++---- test/cuchaz/enigma/inputs/Keep.java | 10 ++++++++++ test/cuchaz/enigma/inputs/constructors/BaseClass.java | 10 ++++++++++ test/cuchaz/enigma/inputs/constructors/Caller.java | 10 ++++++++++ .../enigma/inputs/constructors/DefaultConstructable.java | 10 ++++++++++ test/cuchaz/enigma/inputs/constructors/SubClass.java | 10 ++++++++++ test/cuchaz/enigma/inputs/constructors/SubSubClass.java | 10 ++++++++++ test/cuchaz/enigma/inputs/inheritanceTree/BaseClass.java | 10 ++++++++++ test/cuchaz/enigma/inputs/inheritanceTree/SubclassA.java | 10 ++++++++++ test/cuchaz/enigma/inputs/inheritanceTree/SubclassB.java | 10 ++++++++++ test/cuchaz/enigma/inputs/inheritanceTree/SubsubclassAA.java | 10 ++++++++++ test/cuchaz/enigma/inputs/innerClasses/A_Anonymous.java | 10 ++++++++++ .../enigma/inputs/innerClasses/B_AnonymousWithScopeArgs.java | 10 ++++++++++ test/cuchaz/enigma/inputs/innerClasses/C_ConstructorArgs.java | 10 ++++++++++ test/cuchaz/enigma/inputs/innerClasses/D_Simple.java | 10 ++++++++++ .../enigma/inputs/innerClasses/E_AnonymousWithOuterAccess.java | 10 ++++++++++ test/cuchaz/enigma/inputs/innerClasses/F_ClassTree.java | 10 ++++++++++ test/cuchaz/enigma/inputs/loneClass/LoneClass.java | 10 ++++++++++ test/cuchaz/enigma/inputs/translation/A_Basic.java | 10 ++++++++++ test/cuchaz/enigma/inputs/translation/B_BaseClass.java | 10 ++++++++++ test/cuchaz/enigma/inputs/translation/C_SubClass.java | 10 ++++++++++ test/cuchaz/enigma/inputs/translation/D_AnonymousTesting.java | 10 ++++++++++ test/cuchaz/enigma/inputs/translation/E_Bridges.java | 10 ++++++++++ test/cuchaz/enigma/inputs/translation/F_ObjectMethods.java | 10 ++++++++++ test/cuchaz/enigma/inputs/translation/G_OuterClass.java | 10 ++++++++++ test/cuchaz/enigma/inputs/translation/H_NamelessClass.java | 10 ++++++++++ test/cuchaz/enigma/inputs/translation/I_Generics.java | 10 ++++++++++ 39 files changed, 336 insertions(+), 41 deletions(-) (limited to 'test') diff --git a/test/cuchaz/enigma/TestDeobfed.java b/test/cuchaz/enigma/TestDeobfed.java index ca349d7c..f4093eef 100644 --- a/test/cuchaz/enigma/TestDeobfed.java +++ b/test/cuchaz/enigma/TestDeobfed.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ package cuchaz.enigma; diff --git a/test/cuchaz/enigma/TestDeobfuscator.java b/test/cuchaz/enigma/TestDeobfuscator.java index 26d492d8..bb2a4a5b 100644 --- a/test/cuchaz/enigma/TestDeobfuscator.java +++ b/test/cuchaz/enigma/TestDeobfuscator.java @@ -1,10 +1,9 @@ /******************************************************************************* - * Copyright (c) 2014 Jeff Martin.\ - * + * Copyright (c) 2015 Jeff Martin. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Public License v3.0 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/gpl.html + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html * * Contributors: * Jeff Martin - initial API and implementation diff --git a/test/cuchaz/enigma/TestEntryFactory.java b/test/cuchaz/enigma/TestEntryFactory.java index 754f3081..4aa773b6 100644 --- a/test/cuchaz/enigma/TestEntryFactory.java +++ b/test/cuchaz/enigma/TestEntryFactory.java @@ -1,10 +1,9 @@ /******************************************************************************* - * Copyright (c) 2014 Jeff Martin.\ - * + * Copyright (c) 2015 Jeff Martin. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Public License v3.0 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/gpl.html + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html * * Contributors: * Jeff Martin - initial API and implementation diff --git a/test/cuchaz/enigma/TestInnerClasses.java b/test/cuchaz/enigma/TestInnerClasses.java index 014a4613..41dee4d9 100644 --- a/test/cuchaz/enigma/TestInnerClasses.java +++ b/test/cuchaz/enigma/TestInnerClasses.java @@ -1,10 +1,9 @@ /******************************************************************************* - * Copyright (c) 2014 Jeff Martin. - * + * Copyright (c) 2015 Jeff Martin. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Public License v3.0 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/gpl.html + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html * * Contributors: * Jeff Martin - initial API and implementation diff --git a/test/cuchaz/enigma/TestJarIndexConstructorReferences.java b/test/cuchaz/enigma/TestJarIndexConstructorReferences.java index e1a30226..1c6ead17 100644 --- a/test/cuchaz/enigma/TestJarIndexConstructorReferences.java +++ b/test/cuchaz/enigma/TestJarIndexConstructorReferences.java @@ -1,9 +1,9 @@ /******************************************************************************* - * Copyright (c) 2014 Jeff Martin. + * Copyright (c) 2015 Jeff Martin. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Public License v3.0 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/gpl.html + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html * * Contributors: * Jeff Martin - initial API and implementation diff --git a/test/cuchaz/enigma/TestJarIndexInheritanceTree.java b/test/cuchaz/enigma/TestJarIndexInheritanceTree.java index 6e2c1ad3..04d4fb23 100644 --- a/test/cuchaz/enigma/TestJarIndexInheritanceTree.java +++ b/test/cuchaz/enigma/TestJarIndexInheritanceTree.java @@ -1,9 +1,9 @@ /******************************************************************************* - * Copyright (c) 2014 Jeff Martin. + * Copyright (c) 2015 Jeff Martin. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Public License v3.0 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/gpl.html + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html * * Contributors: * Jeff Martin - initial API and implementation diff --git a/test/cuchaz/enigma/TestJarIndexLoneClass.java b/test/cuchaz/enigma/TestJarIndexLoneClass.java index 0c126ad0..2889241f 100644 --- a/test/cuchaz/enigma/TestJarIndexLoneClass.java +++ b/test/cuchaz/enigma/TestJarIndexLoneClass.java @@ -1,10 +1,9 @@ /******************************************************************************* - * Copyright (c) 2014 Jeff Martin. - * + * Copyright (c) 2015 Jeff Martin. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Public License v3.0 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/gpl.html + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html * * Contributors: * Jeff Martin - initial API and implementation diff --git a/test/cuchaz/enigma/TestSignature.java b/test/cuchaz/enigma/TestSignature.java index 649b76dd..8537adfb 100644 --- a/test/cuchaz/enigma/TestSignature.java +++ b/test/cuchaz/enigma/TestSignature.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ package cuchaz.enigma; import static org.hamcrest.MatcherAssert.*; diff --git a/test/cuchaz/enigma/TestSourceIndex.java b/test/cuchaz/enigma/TestSourceIndex.java index 94bf941d..9329b711 100644 --- a/test/cuchaz/enigma/TestSourceIndex.java +++ b/test/cuchaz/enigma/TestSourceIndex.java @@ -1,10 +1,9 @@ /******************************************************************************* - * Copyright (c) 2014 Jeff Martin. - * + * Copyright (c) 2015 Jeff Martin. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Public License v3.0 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/gpl.html + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html * * Contributors: * Jeff Martin - initial API and implementation diff --git a/test/cuchaz/enigma/TestTokensConstructors.java b/test/cuchaz/enigma/TestTokensConstructors.java index a563f832..07a37caa 100644 --- a/test/cuchaz/enigma/TestTokensConstructors.java +++ b/test/cuchaz/enigma/TestTokensConstructors.java @@ -1,9 +1,9 @@ /******************************************************************************* - * Copyright (c) 2014 Jeff Martin. + * Copyright (c) 2015 Jeff Martin. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Public License v3.0 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/gpl.html + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html * * Contributors: * Jeff Martin - initial API and implementation diff --git a/test/cuchaz/enigma/TestTranslator.java b/test/cuchaz/enigma/TestTranslator.java index 1b617405..668fe05f 100644 --- a/test/cuchaz/enigma/TestTranslator.java +++ b/test/cuchaz/enigma/TestTranslator.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ package cuchaz.enigma; import static cuchaz.enigma.TestEntryFactory.*; diff --git a/test/cuchaz/enigma/TestType.java b/test/cuchaz/enigma/TestType.java index 71aaaee2..01c235b8 100644 --- a/test/cuchaz/enigma/TestType.java +++ b/test/cuchaz/enigma/TestType.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ package cuchaz.enigma; import static cuchaz.enigma.TestEntryFactory.*; diff --git a/test/cuchaz/enigma/TokenChecker.java b/test/cuchaz/enigma/TokenChecker.java index a72c2fc8..7afb4cfe 100644 --- a/test/cuchaz/enigma/TokenChecker.java +++ b/test/cuchaz/enigma/TokenChecker.java @@ -1,9 +1,9 @@ /******************************************************************************* - * Copyright (c) 2014 Jeff Martin. + * Copyright (c) 2015 Jeff Martin. * All rights reserved. This program and the accompanying materials - * are made available under the terms of the GNU Public License v3.0 - * which accompanies this distribution, and is available at - * http://www.gnu.org/licenses/gpl.html + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html * * Contributors: * Jeff Martin - initial API and implementation diff --git a/test/cuchaz/enigma/inputs/Keep.java b/test/cuchaz/enigma/inputs/Keep.java index 390e82fb..f04875f5 100644 --- a/test/cuchaz/enigma/inputs/Keep.java +++ b/test/cuchaz/enigma/inputs/Keep.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ package cuchaz.enigma.inputs; public class Keep { diff --git a/test/cuchaz/enigma/inputs/constructors/BaseClass.java b/test/cuchaz/enigma/inputs/constructors/BaseClass.java index 93453086..65e782a2 100644 --- a/test/cuchaz/enigma/inputs/constructors/BaseClass.java +++ b/test/cuchaz/enigma/inputs/constructors/BaseClass.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ package cuchaz.enigma.inputs.constructors; // none/a diff --git a/test/cuchaz/enigma/inputs/constructors/Caller.java b/test/cuchaz/enigma/inputs/constructors/Caller.java index 57278751..75096ec1 100644 --- a/test/cuchaz/enigma/inputs/constructors/Caller.java +++ b/test/cuchaz/enigma/inputs/constructors/Caller.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ package cuchaz.enigma.inputs.constructors; // none/b diff --git a/test/cuchaz/enigma/inputs/constructors/DefaultConstructable.java b/test/cuchaz/enigma/inputs/constructors/DefaultConstructable.java index 26a3ddbb..655f4da3 100644 --- a/test/cuchaz/enigma/inputs/constructors/DefaultConstructable.java +++ b/test/cuchaz/enigma/inputs/constructors/DefaultConstructable.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ package cuchaz.enigma.inputs.constructors; public class DefaultConstructable { diff --git a/test/cuchaz/enigma/inputs/constructors/SubClass.java b/test/cuchaz/enigma/inputs/constructors/SubClass.java index fecfa2b5..b0fb3e9b 100644 --- a/test/cuchaz/enigma/inputs/constructors/SubClass.java +++ b/test/cuchaz/enigma/inputs/constructors/SubClass.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ package cuchaz.enigma.inputs.constructors; // none/d extends none/a diff --git a/test/cuchaz/enigma/inputs/constructors/SubSubClass.java b/test/cuchaz/enigma/inputs/constructors/SubSubClass.java index ab84161b..50314050 100644 --- a/test/cuchaz/enigma/inputs/constructors/SubSubClass.java +++ b/test/cuchaz/enigma/inputs/constructors/SubSubClass.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ package cuchaz.enigma.inputs.constructors; // none/e extends none/d diff --git a/test/cuchaz/enigma/inputs/inheritanceTree/BaseClass.java b/test/cuchaz/enigma/inputs/inheritanceTree/BaseClass.java index 5b416c41..4f9c5b0e 100644 --- a/test/cuchaz/enigma/inputs/inheritanceTree/BaseClass.java +++ b/test/cuchaz/enigma/inputs/inheritanceTree/BaseClass.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ package cuchaz.enigma.inputs.inheritanceTree; // none/a diff --git a/test/cuchaz/enigma/inputs/inheritanceTree/SubclassA.java b/test/cuchaz/enigma/inputs/inheritanceTree/SubclassA.java index 7a99d516..140d2a81 100644 --- a/test/cuchaz/enigma/inputs/inheritanceTree/SubclassA.java +++ b/test/cuchaz/enigma/inputs/inheritanceTree/SubclassA.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ package cuchaz.enigma.inputs.inheritanceTree; // none/b extends none/a diff --git a/test/cuchaz/enigma/inputs/inheritanceTree/SubclassB.java b/test/cuchaz/enigma/inputs/inheritanceTree/SubclassB.java index c9485d31..99d149bb 100644 --- a/test/cuchaz/enigma/inputs/inheritanceTree/SubclassB.java +++ b/test/cuchaz/enigma/inputs/inheritanceTree/SubclassB.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ package cuchaz.enigma.inputs.inheritanceTree; // none/c extends none/a diff --git a/test/cuchaz/enigma/inputs/inheritanceTree/SubsubclassAA.java b/test/cuchaz/enigma/inputs/inheritanceTree/SubsubclassAA.java index afd03ac4..2e414b75 100644 --- a/test/cuchaz/enigma/inputs/inheritanceTree/SubsubclassAA.java +++ b/test/cuchaz/enigma/inputs/inheritanceTree/SubsubclassAA.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ package cuchaz.enigma.inputs.inheritanceTree; // none/d extends none/b diff --git a/test/cuchaz/enigma/inputs/innerClasses/A_Anonymous.java b/test/cuchaz/enigma/inputs/innerClasses/A_Anonymous.java index f7118f63..f6444396 100644 --- a/test/cuchaz/enigma/inputs/innerClasses/A_Anonymous.java +++ b/test/cuchaz/enigma/inputs/innerClasses/A_Anonymous.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ package cuchaz.enigma.inputs.innerClasses; public class A_Anonymous { diff --git a/test/cuchaz/enigma/inputs/innerClasses/B_AnonymousWithScopeArgs.java b/test/cuchaz/enigma/inputs/innerClasses/B_AnonymousWithScopeArgs.java index 42fba9a8..d78be847 100644 --- a/test/cuchaz/enigma/inputs/innerClasses/B_AnonymousWithScopeArgs.java +++ b/test/cuchaz/enigma/inputs/innerClasses/B_AnonymousWithScopeArgs.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ package cuchaz.enigma.inputs.innerClasses; public class B_AnonymousWithScopeArgs { diff --git a/test/cuchaz/enigma/inputs/innerClasses/C_ConstructorArgs.java b/test/cuchaz/enigma/inputs/innerClasses/C_ConstructorArgs.java index 8fa6c5b8..eb03489d 100644 --- a/test/cuchaz/enigma/inputs/innerClasses/C_ConstructorArgs.java +++ b/test/cuchaz/enigma/inputs/innerClasses/C_ConstructorArgs.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ package cuchaz.enigma.inputs.innerClasses; @SuppressWarnings("unused") diff --git a/test/cuchaz/enigma/inputs/innerClasses/D_Simple.java b/test/cuchaz/enigma/inputs/innerClasses/D_Simple.java index c4fc0ef9..0e9bf827 100644 --- a/test/cuchaz/enigma/inputs/innerClasses/D_Simple.java +++ b/test/cuchaz/enigma/inputs/innerClasses/D_Simple.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ package cuchaz.enigma.inputs.innerClasses; public class D_Simple { diff --git a/test/cuchaz/enigma/inputs/innerClasses/E_AnonymousWithOuterAccess.java b/test/cuchaz/enigma/inputs/innerClasses/E_AnonymousWithOuterAccess.java index e1de53cb..255434d1 100644 --- a/test/cuchaz/enigma/inputs/innerClasses/E_AnonymousWithOuterAccess.java +++ b/test/cuchaz/enigma/inputs/innerClasses/E_AnonymousWithOuterAccess.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ package cuchaz.enigma.inputs.innerClasses; public class E_AnonymousWithOuterAccess { diff --git a/test/cuchaz/enigma/inputs/innerClasses/F_ClassTree.java b/test/cuchaz/enigma/inputs/innerClasses/F_ClassTree.java index 6552d8a6..7d1dab41 100644 --- a/test/cuchaz/enigma/inputs/innerClasses/F_ClassTree.java +++ b/test/cuchaz/enigma/inputs/innerClasses/F_ClassTree.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ package cuchaz.enigma.inputs.innerClasses; diff --git a/test/cuchaz/enigma/inputs/loneClass/LoneClass.java b/test/cuchaz/enigma/inputs/loneClass/LoneClass.java index 18c716e9..bf264fa5 100644 --- a/test/cuchaz/enigma/inputs/loneClass/LoneClass.java +++ b/test/cuchaz/enigma/inputs/loneClass/LoneClass.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ package cuchaz.enigma.inputs.loneClass; public class LoneClass { diff --git a/test/cuchaz/enigma/inputs/translation/A_Basic.java b/test/cuchaz/enigma/inputs/translation/A_Basic.java index 89307630..26acac8a 100644 --- a/test/cuchaz/enigma/inputs/translation/A_Basic.java +++ b/test/cuchaz/enigma/inputs/translation/A_Basic.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ package cuchaz.enigma.inputs.translation; public class A_Basic { diff --git a/test/cuchaz/enigma/inputs/translation/B_BaseClass.java b/test/cuchaz/enigma/inputs/translation/B_BaseClass.java index 44fbc8db..035e3299 100644 --- a/test/cuchaz/enigma/inputs/translation/B_BaseClass.java +++ b/test/cuchaz/enigma/inputs/translation/B_BaseClass.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ package cuchaz.enigma.inputs.translation; public class B_BaseClass { diff --git a/test/cuchaz/enigma/inputs/translation/C_SubClass.java b/test/cuchaz/enigma/inputs/translation/C_SubClass.java index 8fe0b799..6026a8d5 100644 --- a/test/cuchaz/enigma/inputs/translation/C_SubClass.java +++ b/test/cuchaz/enigma/inputs/translation/C_SubClass.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ package cuchaz.enigma.inputs.translation; public class C_SubClass extends B_BaseClass { diff --git a/test/cuchaz/enigma/inputs/translation/D_AnonymousTesting.java b/test/cuchaz/enigma/inputs/translation/D_AnonymousTesting.java index a1166e20..a1827f98 100644 --- a/test/cuchaz/enigma/inputs/translation/D_AnonymousTesting.java +++ b/test/cuchaz/enigma/inputs/translation/D_AnonymousTesting.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ package cuchaz.enigma.inputs.translation; import java.util.ArrayList; diff --git a/test/cuchaz/enigma/inputs/translation/E_Bridges.java b/test/cuchaz/enigma/inputs/translation/E_Bridges.java index dac50d39..769eb70e 100644 --- a/test/cuchaz/enigma/inputs/translation/E_Bridges.java +++ b/test/cuchaz/enigma/inputs/translation/E_Bridges.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ package cuchaz.enigma.inputs.translation; import java.util.Iterator; diff --git a/test/cuchaz/enigma/inputs/translation/F_ObjectMethods.java b/test/cuchaz/enigma/inputs/translation/F_ObjectMethods.java index 4e091797..32c246cb 100644 --- a/test/cuchaz/enigma/inputs/translation/F_ObjectMethods.java +++ b/test/cuchaz/enigma/inputs/translation/F_ObjectMethods.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ package cuchaz.enigma.inputs.translation; public class F_ObjectMethods { diff --git a/test/cuchaz/enigma/inputs/translation/G_OuterClass.java b/test/cuchaz/enigma/inputs/translation/G_OuterClass.java index 0856afed..a2e0dafb 100644 --- a/test/cuchaz/enigma/inputs/translation/G_OuterClass.java +++ b/test/cuchaz/enigma/inputs/translation/G_OuterClass.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ package cuchaz.enigma.inputs.translation; diff --git a/test/cuchaz/enigma/inputs/translation/H_NamelessClass.java b/test/cuchaz/enigma/inputs/translation/H_NamelessClass.java index 5802d789..1b718a54 100644 --- a/test/cuchaz/enigma/inputs/translation/H_NamelessClass.java +++ b/test/cuchaz/enigma/inputs/translation/H_NamelessClass.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ package cuchaz.enigma.inputs.translation; diff --git a/test/cuchaz/enigma/inputs/translation/I_Generics.java b/test/cuchaz/enigma/inputs/translation/I_Generics.java index 191931a8..3490f9d9 100644 --- a/test/cuchaz/enigma/inputs/translation/I_Generics.java +++ b/test/cuchaz/enigma/inputs/translation/I_Generics.java @@ -1,3 +1,13 @@ +/******************************************************************************* + * Copyright (c) 2015 Jeff Martin. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public + * License v3.0 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * Contributors: + * Jeff Martin - initial API and implementation + ******************************************************************************/ package cuchaz.enigma.inputs.translation; import java.util.List; -- cgit v1.2.3 From c7a3de184dc51526ee157d47981a74ffba284f5d Mon Sep 17 00:00:00 2001 From: Cuchaz Date: Sun, 24 May 2015 11:23:36 -0400 Subject: fix broken tests, and one broken function. =) --- .../cuchaz/enigma/TestJarIndexInheritanceTree.java | 27 +++++++++++++++------- test/cuchaz/enigma/TestJarIndexLoneClass.java | 10 ++++---- 2 files changed, 24 insertions(+), 13 deletions(-) (limited to 'test') diff --git a/test/cuchaz/enigma/TestJarIndexInheritanceTree.java b/test/cuchaz/enigma/TestJarIndexInheritanceTree.java index 04d4fb23..d3c23eaf 100644 --- a/test/cuchaz/enigma/TestJarIndexInheritanceTree.java +++ b/test/cuchaz/enigma/TestJarIndexInheritanceTree.java @@ -10,9 +10,19 @@ ******************************************************************************/ package cuchaz.enigma; -import static cuchaz.enigma.TestEntryFactory.*; -import static org.hamcrest.MatcherAssert.*; -import static org.hamcrest.Matchers.*; +import static cuchaz.enigma.TestEntryFactory.newBehaviorReferenceByConstructor; +import static cuchaz.enigma.TestEntryFactory.newBehaviorReferenceByMethod; +import static cuchaz.enigma.TestEntryFactory.newClass; +import static cuchaz.enigma.TestEntryFactory.newConstructor; +import static cuchaz.enigma.TestEntryFactory.newField; +import static cuchaz.enigma.TestEntryFactory.newFieldReferenceByConstructor; +import static cuchaz.enigma.TestEntryFactory.newFieldReferenceByMethod; +import static cuchaz.enigma.TestEntryFactory.newMethod; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.empty; +import static org.hamcrest.Matchers.is; import java.util.Collection; import java.util.Set; @@ -33,6 +43,7 @@ public class TestJarIndexInheritanceTree { private JarIndex m_index; + private ClassEntry m_objectClass = newClass("java/lang/Object"); private ClassEntry m_baseClass = newClass("none/a"); private ClassEntry m_subClassA = newClass("none/b"); private ClassEntry m_subClassAA = newClass("none/d"); @@ -63,8 +74,8 @@ public class TestJarIndexInheritanceTree { TranslationIndex index = m_index.getTranslationIndex(); // base class - assertThat(index.getSuperclass(m_baseClass), is(nullValue())); - assertThat(index.getAncestry(m_baseClass), is(empty())); + assertThat(index.getSuperclass(m_baseClass), is(m_objectClass)); + assertThat(index.getAncestry(m_baseClass), contains(m_objectClass)); assertThat(index.getSubclass(m_baseClass), containsInAnyOrder( m_subClassA, m_subClassB @@ -72,17 +83,17 @@ public class TestJarIndexInheritanceTree { // subclass a assertThat(index.getSuperclass(m_subClassA), is(m_baseClass)); - assertThat(index.getAncestry(m_subClassA), contains(m_baseClass)); + assertThat(index.getAncestry(m_subClassA), contains(m_baseClass, m_objectClass)); assertThat(index.getSubclass(m_subClassA), contains(m_subClassAA)); // subclass aa assertThat(index.getSuperclass(m_subClassAA), is(m_subClassA)); - assertThat(index.getAncestry(m_subClassAA), contains(m_subClassA, m_baseClass)); + assertThat(index.getAncestry(m_subClassAA), contains(m_subClassA, m_baseClass, m_objectClass)); assertThat(index.getSubclass(m_subClassAA), is(empty())); // subclass b assertThat(index.getSuperclass(m_subClassB), is(m_baseClass)); - assertThat(index.getAncestry(m_subClassB), contains(m_baseClass)); + assertThat(index.getAncestry(m_subClassB), contains(m_baseClass, m_objectClass)); assertThat(index.getSubclass(m_subClassB), is(empty())); } diff --git a/test/cuchaz/enigma/TestJarIndexLoneClass.java b/test/cuchaz/enigma/TestJarIndexLoneClass.java index 2889241f..c97b2efa 100644 --- a/test/cuchaz/enigma/TestJarIndexLoneClass.java +++ b/test/cuchaz/enigma/TestJarIndexLoneClass.java @@ -52,10 +52,10 @@ public class TestJarIndexLoneClass { @Test public void translationIndex() { - assertThat(m_index.getTranslationIndex().getSuperclass(new ClassEntry("none/a")), is(nullValue())); - assertThat(m_index.getTranslationIndex().getSuperclass(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(nullValue())); - assertThat(m_index.getTranslationIndex().getAncestry(new ClassEntry("none/a")), is(empty())); - assertThat(m_index.getTranslationIndex().getAncestry(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(empty())); + assertThat(m_index.getTranslationIndex().getSuperclass(new ClassEntry("none/a")), is(new ClassEntry("java/lang/Object"))); + assertThat(m_index.getTranslationIndex().getSuperclass(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(new ClassEntry("java/lang/Object"))); + assertThat(m_index.getTranslationIndex().getAncestry(new ClassEntry("none/a")), contains(new ClassEntry("java/lang/Object"))); + assertThat(m_index.getTranslationIndex().getAncestry(new ClassEntry("cuchaz/enigma/inputs/Keep")), contains(new ClassEntry("java/lang/Object"))); assertThat(m_index.getTranslationIndex().getSubclass(new ClassEntry("none/a")), is(empty())); assertThat(m_index.getTranslationIndex().getSubclass(new ClassEntry("cuchaz/enigma/inputs/Keep")), is(empty())); } @@ -152,7 +152,7 @@ public class TestJarIndexLoneClass { } @Test - public void contains() { + public void testContains() { assertThat(m_index.containsObfClass(newClass("none/a")), is(true)); assertThat(m_index.containsObfClass(newClass("none/b")), is(false)); assertThat(m_index.containsObfField(newField("none/a", "a", "Ljava/lang/String;")), is(true)); -- cgit v1.2.3