From a88175ffc95792b88a8724f66db6dda2b8cc32ee Mon Sep 17 00:00:00 2001 From: gegy1000 Date: Tue, 17 Jul 2018 19:14:08 +0200 Subject: ASM Based Class Translator (#1) * Initial port to ASM * Package updates * Annotation + inner class translation * Fix inner class mapping * More bytecode translation * Signature refactoring * Fix highlighting of mapped names * Fix parameter name offset * Fix anonymous class generation * Fix issues with inner class signature transformation * Fix bridged method detection * Fix compile issues * Resolve all failed tests * Apply deobfuscated name to transformed classes * Fix class signatures not being translated * Fix frame array type translation * Fix frame array type translation * Fix array translation in method calls * Fix method reference and bridge detection * Fix handling of null deobf mappings * Parameter translation in interfaces * Fix enum parameter index offset * Fix parsed local variable indexing * Fix stackoverflow on rebuilding method names * Ignore invalid decompiled variable indices * basic source jar * Output directly to file on source export * Make decompile parallel * fix incorrect super calls * Use previous save state to delete old mapping files * Fix old mappings not properly being removed * Fix old mappings not properly being removed * make isMethodProvider public (cherry picked from commit ebad6a9) * speed up Deobfuscator's getSources by using a single TranslatingTypeloader and caching the ClassLoaderTypeloader * ignore .idea project folders * move SynchronizedTypeLoader to a non-inner * fix signature remap of inners for now * index & resolve method/field references for usages view * Allow reader/writer subclasses to provide the underlying file operations * fix giving obf classes a name not removing them from the panel * buffer the ParsedJar class entry inputstream, allow use with a jarinputstream * make CachingClasspathTypeLoader public * make CachingClasspathTypeLoader public * support enum switches with obfuscated SwitchMaps --- .../java/cuchaz/enigma/TestTokensConstructors.java | 90 +++++++++++----------- 1 file changed, 43 insertions(+), 47 deletions(-) (limited to 'src/test/java/cuchaz/enigma/TestTokensConstructors.java') diff --git a/src/test/java/cuchaz/enigma/TestTokensConstructors.java b/src/test/java/cuchaz/enigma/TestTokensConstructors.java index e40d5fd..0e98da7 100644 --- a/src/test/java/cuchaz/enigma/TestTokensConstructors.java +++ b/src/test/java/cuchaz/enigma/TestTokensConstructors.java @@ -11,131 +11,127 @@ package cuchaz.enigma; -import cuchaz.enigma.mapping.BehaviorEntry; +import cuchaz.enigma.mapping.entry.MethodEntry; import org.junit.Test; import java.util.jar.JarFile; -import static cuchaz.enigma.TestEntryFactory.newBehaviorReferenceByConstructor; import static cuchaz.enigma.TestEntryFactory.newBehaviorReferenceByMethod; -import static cuchaz.enigma.TestEntryFactory.newConstructor; +import static cuchaz.enigma.TestEntryFactory.newMethod; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.nullValue; +import static org.hamcrest.Matchers.*; public class TestTokensConstructors extends TokenChecker { public TestTokensConstructors() - throws Exception { + throws Exception { super(new JarFile("build/test-obf/constructors.jar")); } @Test public void baseDeclarations() { - assertThat(getDeclarationToken(newConstructor("a", "()V")), is("a")); - assertThat(getDeclarationToken(newConstructor("a", "(I)V")), is("a")); + assertThat(getDeclarationToken(newMethod("a", "", "()V")), is("a")); + assertThat(getDeclarationToken(newMethod("a", "", "(I)V")), is("a")); } @Test public void subDeclarations() { - assertThat(getDeclarationToken(newConstructor("d", "()V")), is("d")); - assertThat(getDeclarationToken(newConstructor("d", "(I)V")), is("d")); - assertThat(getDeclarationToken(newConstructor("d", "(II)V")), is("d")); - assertThat(getDeclarationToken(newConstructor("d", "(III)V")), is("d")); + assertThat(getDeclarationToken(newMethod("d", "", "()V")), is("d")); + assertThat(getDeclarationToken(newMethod("d", "", "(I)V")), is("d")); + assertThat(getDeclarationToken(newMethod("d", "", "(II)V")), is("d")); + assertThat(getDeclarationToken(newMethod("d", "", "(III)V")), is("d")); } @Test public void subsubDeclarations() { - assertThat(getDeclarationToken(newConstructor("e", "(I)V")), is("e")); + assertThat(getDeclarationToken(newMethod("e", "", "(I)V")), is("e")); } @Test public void defaultDeclarations() { - assertThat(getDeclarationToken(newConstructor("c", "()V")), nullValue()); + assertThat(getDeclarationToken(newMethod("c", "", "()V")), nullValue()); } @Test public void baseDefaultReferences() { - BehaviorEntry source = newConstructor("a", "()V"); + MethodEntry source = newMethod("a", "", "()V"); assertThat( - getReferenceTokens(newBehaviorReferenceByMethod(source, "b", "a", "()V")), - containsInAnyOrder("a") + getReferenceTokens(newBehaviorReferenceByMethod(source, "b", "a", "()V")), + containsInAnyOrder("a") ); assertThat( - getReferenceTokens(newBehaviorReferenceByConstructor(source, "d", "()V")), - is(empty()) // implicit call, not decompiled to token + getReferenceTokens(newBehaviorReferenceByMethod(source, "d", "", "()V")), + is(empty()) // implicit call, not decompiled to token ); assertThat( - getReferenceTokens(newBehaviorReferenceByConstructor(source, "d", "(III)V")), - is(empty()) // implicit call, not decompiled to token + getReferenceTokens(newBehaviorReferenceByMethod(source, "d", "", "(III)V")), + is(empty()) // implicit call, not decompiled to token ); } @Test public void baseIntReferences() { - BehaviorEntry source = newConstructor("a", "(I)V"); + MethodEntry source = newMethod("a", "", "(I)V"); assertThat( - getReferenceTokens(newBehaviorReferenceByMethod(source, "b", "b", "()V")), - containsInAnyOrder("a") + getReferenceTokens(newBehaviorReferenceByMethod(source, "b", "b", "()V")), + containsInAnyOrder("a") ); } @Test public void subDefaultReferences() { - BehaviorEntry source = newConstructor("d", "()V"); + MethodEntry source = newMethod("d", "", "()V"); assertThat( - getReferenceTokens(newBehaviorReferenceByMethod(source, "b", "c", "()V")), - containsInAnyOrder("d") + getReferenceTokens(newBehaviorReferenceByMethod(source, "b", "c", "()V")), + containsInAnyOrder("d") ); assertThat( - getReferenceTokens(newBehaviorReferenceByConstructor(source, "d", "(I)V")), - containsInAnyOrder("this") + getReferenceTokens(newBehaviorReferenceByMethod(source, "d", "", "(I)V")), + containsInAnyOrder("this") ); } @Test public void subIntReferences() { - BehaviorEntry source = newConstructor("d", "(I)V"); + MethodEntry source = newMethod("d", "", "(I)V"); assertThat(getReferenceTokens( - newBehaviorReferenceByMethod(source, "b", "d", "()V")), - containsInAnyOrder("d") + newBehaviorReferenceByMethod(source, "b", "d", "()V")), + containsInAnyOrder("d") ); assertThat(getReferenceTokens( - newBehaviorReferenceByConstructor(source, "d", "(II)V")), - containsInAnyOrder("this") + newBehaviorReferenceByMethod(source, "d", "", "(II)V")), + containsInAnyOrder("this") ); assertThat(getReferenceTokens( - newBehaviorReferenceByConstructor(source, "e", "(I)V")), - containsInAnyOrder("super") + newBehaviorReferenceByMethod(source, "e", "", "(I)V")), + containsInAnyOrder("super") ); } @Test public void subIntIntReferences() { - BehaviorEntry source = newConstructor("d", "(II)V"); + MethodEntry source = newMethod("d", "", "(II)V"); assertThat( - getReferenceTokens(newBehaviorReferenceByMethod(source, "b", "e", "()V")), - containsInAnyOrder("d") + getReferenceTokens(newBehaviorReferenceByMethod(source, "b", "e", "()V")), + containsInAnyOrder("d") ); } @Test public void subsubIntReferences() { - BehaviorEntry source = newConstructor("e", "(I)V"); + MethodEntry source = newMethod("e", "", "(I)V"); assertThat( - getReferenceTokens(newBehaviorReferenceByMethod(source, "b", "f", "()V")), - containsInAnyOrder("e") + getReferenceTokens(newBehaviorReferenceByMethod(source, "b", "f", "()V")), + containsInAnyOrder("e") ); } @Test public void defaultConstructableReferences() { - BehaviorEntry source = newConstructor("c", "()V"); + MethodEntry source = newMethod("c", "", "()V"); assertThat( - getReferenceTokens(newBehaviorReferenceByMethod(source, "b", "g", "()V")), - containsInAnyOrder("c") + getReferenceTokens(newBehaviorReferenceByMethod(source, "b", "g", "()V")), + containsInAnyOrder("c") ); } } -- cgit v1.2.3