-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
enigma/src/test/java/org/quiltmc/enigma/TestTokensSimilarClassNames.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.quiltmc.enigma; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.quiltmc.enigma.api.Enigma; | ||
import org.quiltmc.enigma.api.EnigmaProject; | ||
import org.quiltmc.enigma.api.ProgressListener; | ||
import org.quiltmc.enigma.api.class_provider.JarClassProvider; | ||
import org.quiltmc.enigma.api.source.DecompiledClassSource; | ||
import org.quiltmc.enigma.api.source.Decompiler; | ||
import org.quiltmc.enigma.api.source.Decompilers; | ||
import org.quiltmc.enigma.api.source.SourceSettings; | ||
import org.quiltmc.enigma.api.source.Token; | ||
import org.quiltmc.enigma.api.source.TokenType; | ||
import org.quiltmc.enigma.api.translation.representation.entry.ClassEntry; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.util.Collection; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
|
||
public class TestTokensSimilarClassNames { | ||
private static final Path JAR = TestUtil.obfJar("similar_class_names"); | ||
|
||
@Test | ||
public void testSimilarClassNames() throws IOException { | ||
EnigmaProject project = openProject(); | ||
ClassEntry alpha = TestEntryFactory.newClass(getClassName("Alpha")); | ||
Decompiler decompiler = Decompilers.VINEFLOWER.create(new JarClassProvider(JAR), new SourceSettings(false, false)); | ||
DecompiledClassSource decomp = new DecompiledClassSource(alpha, decompiler.getUndocumentedSource(getClassName("Alpha")).index()); | ||
DecompiledClassSource source = decomp.remapSource(project, project.getRemapper().getDeobfuscator()); | ||
Collection<Token> tokens = source.getHighlightedTokens().get(TokenType.OBFUSCATED); | ||
for (Token token : tokens) { | ||
assertFalse(token.text.startsWith("Alphabet")); | ||
} | ||
} | ||
|
||
private static String getClassName(String className) { | ||
return "org/quiltmc/enigma/input/similar_class_names/" + className; | ||
} | ||
|
||
private static EnigmaProject openProject() { | ||
try { | ||
Enigma enigma = Enigma.create(); | ||
return enigma.openJar(JAR, new JarClassProvider(JAR), ProgressListener.createEmpty()); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
enigma/src/test/java/org/quiltmc/enigma/input/similar_class_names/Alpha.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.quiltmc.enigma.input.similar_class_names; | ||
|
||
public interface Alpha { | ||
char get(int n); | ||
} |
14 changes: 14 additions & 0 deletions
14
enigma/src/test/java/org/quiltmc/enigma/input/similar_class_names/Alphabet.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.quiltmc.enigma.input.similar_class_names; | ||
|
||
public class Alphabet { | ||
public static class Inner { | ||
public Alpha get() { | ||
return new Alpha() { | ||
@Override | ||
public char get(int n) { | ||
return 0; | ||
} | ||
}; | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
enigma/src/test/java/org/quiltmc/enigma/input/similar_class_names/Caller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.quiltmc.enigma.input.similar_class_names; | ||
|
||
public class Caller { | ||
public void call() { | ||
new Alphabet.Inner().get(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
enigma/src/test/resources/proguard-similar_class_names-test.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
-repackageclasses | ||
-allowaccessmodification | ||
-dontoptimize | ||
-dontshrink | ||
-keepparameternames | ||
-keepattributes | ||
-keep class org.quiltmc.enigma.input.Keep | ||
-keep class org.quiltmc.enigma.input.similar_class_names.* | ||
|