-
-
Notifications
You must be signed in to change notification settings - Fork 32
Repair inner class nesting when stripped by an obfuscator #362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
RDIL
wants to merge
2
commits into
QuiltMC:develop/2.8
Choose a base branch
from
RDIL:reece/inner-classes
base: develop/2.8
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
61 changes: 61 additions & 0 deletions
61
enigma/src/main/java/org/quiltmc/enigma/api/analysis/index/jar/InnerClassIndex.java
This file contains hidden or 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,61 @@ | ||
| package org.quiltmc.enigma.api.analysis.index.jar; | ||
|
|
||
| import org.jspecify.annotations.NonNull; | ||
| import org.quiltmc.enigma.api.translation.representation.entry.ClassDefEntry; | ||
| import org.quiltmc.enigma.api.translation.representation.entry.ClassEntry; | ||
|
|
||
| import java.util.HashSet; | ||
| import java.util.Set; | ||
|
|
||
| /** | ||
| * An index of the classes a jar declares nested with the {@code InnerClasses} attribute. | ||
| * | ||
| * <p>Enigma takes nesting from class names, where {@code a/B$C} is an inner class of {@code a/B}. | ||
| * Decompilers take it from the {@code InnerClasses} attribute, and only put a class' source inside another | ||
| * class' source when that attribute says so. An obfuscator that strips the attribute without renaming makes | ||
| * the two disagree: the class still reads as nested, but it decompiles to a file of its own. | ||
| * | ||
| * <p>A class counts as {@linkplain #isNestedInSource nested in source} when any class in the jar declares | ||
| * an {@code InnerClasses} record naming it. The compiler writes that record in the nested class, in its | ||
| * enclosing class and in every class that references it, so one record anywhere in the jar is enough. | ||
| */ | ||
| public class InnerClassIndex implements JarIndexer { | ||
| private final Set<ClassEntry> nestedInSource = new HashSet<>(); | ||
|
|
||
| @Override | ||
| public void indexInnerClass(ClassDefEntry classEntry, @NonNull InnerClassData innerClassData) { | ||
| this.nestedInSource.add(new ClassEntry(innerClassData.name())); | ||
| } | ||
|
|
||
| /** | ||
| * Returns whether the passed {@code entry}'s source is written inside another class' source, i.e. whether the jar | ||
| * declares it nested with an {@code InnerClasses} record. A class whose name looks nested but that has no | ||
| * such record yields {@code false}. | ||
| * | ||
| * @param entry the class to check | ||
| */ | ||
| public boolean isNestedInSource(ClassEntry entry) { | ||
| return this.nestedInSource.contains(entry); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the class whose source contains the passed {@code entry}'s, which is {@code entry} itself unless it is | ||
| * {@linkplain #isNestedInSource nested in source}. This is the class to decompile, to open in an editor | ||
| * and to index tokens against when navigating to {@code entry}. | ||
| * | ||
| * @param entry the class to find the source of | ||
| */ | ||
| public ClassEntry getSourceRoot(ClassEntry entry) { | ||
| ClassEntry root = entry; | ||
| while (root.getOuterClass() != null && this.isNestedInSource(root)) { | ||
| root = root.getOuterClass(); | ||
| } | ||
|
|
||
| return root; | ||
| } | ||
|
|
||
| @Override | ||
| public String getTranslationKey() { | ||
| return "progress.jar.indexing.process.inner_classes"; | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.