Skip to content

Commit

Permalink
add mappings indexing (#156)
Browse files Browse the repository at this point in the history
* add mappings indexing

* add package name index

* add reindexing

* add translations

* clean up mappings indexing, implement @IotaBread's suggestion

* implement new system for getting indexers onto JarIndex

* fix commands
  • Loading branch information
ix0rai authored Oct 10, 2023
1 parent facf43e commit 3ddbccd
Show file tree
Hide file tree
Showing 58 changed files with 544 additions and 241 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.quiltmc.enigma.command;

import org.quiltmc.enigma.api.EnigmaProject;
import org.quiltmc.enigma.api.analysis.index.JarIndex;
import org.quiltmc.enigma.api.analysis.index.jar.JarIndex;
import org.quiltmc.enigma.api.analysis.index.jar.PackageVisibilityIndex;
import org.quiltmc.enigma.api.translation.representation.entry.ClassEntry;
import org.tinylog.Logger;

Expand Down Expand Up @@ -38,7 +39,7 @@ public static void run(Path fileJarIn, Path fileMappings) throws Exception {

boolean error = false;

for (Set<ClassEntry> partition : idx.getPackageVisibilityIndex().getPartitions()) {
for (Set<ClassEntry> partition : idx.getIndex(PackageVisibilityIndex.class).getPartitions()) {
long packages = partition.stream()
.map(project.getMapper()::deobfuscate)
.map(ClassEntry::getPackageName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.quiltmc.enigma.api.EnigmaProfile;
import org.quiltmc.enigma.api.EnigmaProject;
import org.quiltmc.enigma.api.ProgressListener;
import org.quiltmc.enigma.api.analysis.index.JarIndex;
import org.quiltmc.enigma.api.analysis.index.jar.JarIndex;
import org.quiltmc.enigma.api.EnigmaPlugin;
import org.quiltmc.enigma.api.class_provider.CachingClassProvider;
import org.quiltmc.enigma.api.class_provider.ClasspathClassProvider;
Expand Down Expand Up @@ -155,7 +155,7 @@ public static EnigmaProject openProject(Path fileJarIn, Path fileMappings, Enigm

EntryTree<EntryMapping> mappings = readMappings(fileMappings, progress);

project.setMappings(mappings);
project.setMappings(mappings, new ConsoleProgressListener());
}

return project;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.quiltmc.enigma.command;

import org.quiltmc.enigma.api.ProgressListener;
import org.quiltmc.enigma.api.analysis.index.JarIndex;
import org.quiltmc.enigma.api.analysis.index.jar.JarIndex;
import org.quiltmc.enigma.api.translation.mapping.EntryMapping;
import org.quiltmc.enigma.api.translation.mapping.serde.MappingFileNameFormat;
import org.quiltmc.enigma.api.translation.mapping.serde.MappingSaveParameters;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.quiltmc.enigma.api.EnigmaProfile;
import org.quiltmc.enigma.api.EnigmaProject;
import org.quiltmc.enigma.api.ProgressListener;
import org.quiltmc.enigma.api.analysis.index.EntryIndex;
import org.quiltmc.enigma.api.analysis.index.jar.EntryIndex;
import org.quiltmc.enigma.api.EnigmaPlugin;
import org.quiltmc.enigma.api.service.NameProposalService;
import org.quiltmc.enigma.api.translation.ProposingTranslator;
Expand Down Expand Up @@ -95,7 +95,7 @@ public static EntryTree<EntryMapping> exec(NameProposalService[] nameProposalSer

EntryRemapper mapper = project.getMapper();
Translator translator = new ProposingTranslator(mapper, nameProposalServices);
EntryIndex index = project.getJarIndex().getEntryIndex();
EntryIndex index = project.getJarIndex().getIndex(EntryIndex.class);

Logger.info("Proposing class names...");
int classes = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.quiltmc.enigma.command;

import org.quiltmc.enigma.api.analysis.index.BridgeMethodIndex;
import org.quiltmc.enigma.api.analysis.index.JarIndex;
import org.quiltmc.enigma.api.analysis.index.jar.BridgeMethodIndex;
import org.quiltmc.enigma.api.analysis.index.jar.JarIndex;
import org.quiltmc.enigma.api.translation.MappingTranslator;
import org.quiltmc.enigma.api.translation.Translator;
import org.quiltmc.enigma.api.translation.mapping.EntryMapping;
Expand Down Expand Up @@ -71,7 +71,7 @@ public static void run(Path jar, Path sourcePath, String resultFormat, Path outp
public static EntryTree<EntryMapping> run(JarIndex jarIndex, EntryTree<EntryMapping> source, boolean trackDelta) throws IOException, MappingParseException {
EntryTree<EntryMapping> result = new HashEntryTree<>();

BridgeMethodIndex bridgeMethodIndex = jarIndex.getBridgeMethodIndex();
BridgeMethodIndex bridgeMethodIndex = jarIndex.getIndex(BridgeMethodIndex.class);
Translator translator = new MappingTranslator(source, jarIndex.getEntryResolver());

// Copy all non-specialized methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static void main(String[] args) {
mappings = EntryRemapper.empty(project.getJarIndex());
} else {
Logger.info("Reading mappings...");
mappings = EntryRemapper.mapped(project.getJarIndex(), mappingFormat.read(mappingsFile));
mappings = EntryRemapper.mapped(project.getJarIndex(), project.getMappingsIndex(), mappingFormat.read(mappingsFile));
}

PrintWriter log = new PrintWriter(Files.newBufferedWriter(logFile));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import org.quiltmc.enigma.api.Enigma;
import org.quiltmc.enigma.api.EnigmaProfile;
import org.quiltmc.enigma.api.EnigmaProject;
import org.quiltmc.enigma.api.ProgressListener;
import org.quiltmc.enigma.api.analysis.index.jar.EntryIndex;
import org.quiltmc.enigma.api.analysis.tree.ClassImplementationsTreeNode;
import org.quiltmc.enigma.api.analysis.tree.ClassInheritanceTreeNode;
import org.quiltmc.enigma.api.analysis.tree.ClassReferenceTreeNode;
Expand Down Expand Up @@ -157,7 +159,7 @@ public CompletableFuture<Void> openMappings(MappingFormat format, Path path) {
return ProgressDialog.runOffThread(this.gui, progress -> {
try {
EntryTree<EntryMapping> mappings = format.read(path);
this.project.setMappings(mappings);
this.project.setMappings(mappings, progress);

this.loadedMappingFormat = format;
this.loadedMappingPath = path;
Expand All @@ -175,7 +177,7 @@ public CompletableFuture<Void> openMappings(MappingFormat format, Path path) {
public void openMappings(EntryTree<EntryMapping> mappings) {
if (this.project == null) return;

this.project.setMappings(mappings);
this.project.setMappings(mappings, new ProgressDialog(this.gui.getFrame()));
this.refreshClasses();
this.chp.invalidateJavadoc();
}
Expand Down Expand Up @@ -225,7 +227,7 @@ public CompletableFuture<Void> saveMappings(Path path, MappingFormat format) {
public void closeMappings() {
if (this.project == null) return;

this.project.setMappings(null);
this.project.setMappings(null, ProgressListener.none());

this.gui.setMappingsFile(null);
this.refreshClasses();
Expand Down Expand Up @@ -408,7 +410,7 @@ public void refreshClasses() {
public void addSeparatedClasses(List<ClassEntry> obfClasses, List<ClassEntry> deobfClasses) {
EntryRemapper mapper = this.project.getMapper();

Collection<ClassEntry> classes = this.project.getJarIndex().getEntryIndex().getClasses();
Collection<ClassEntry> classes = this.project.getJarIndex().getIndex(EntryIndex.class).getClasses();
Stream<ClassEntry> visibleClasses = classes.stream()
.filter(entry -> !entry.isInnerClass());

Expand Down Expand Up @@ -613,7 +615,7 @@ public void createClient(String username, String ip, int port, char[] password)
}

public void createServer(int port, char[] password) throws IOException {
this.server = new IntegratedEnigmaServer(this.project.getJarChecksum(), password, EntryRemapper.mapped(this.project.getJarIndex(), new HashEntryTree<>(this.project.getMapper().getObfToDeobf())), port);
this.server = new IntegratedEnigmaServer(this.project.getJarChecksum(), password, EntryRemapper.mapped(this.project.getJarIndex(), this.project.getMappingsIndex(), new HashEntryTree<>(this.project.getMapper().getObfToDeobf())), port);
this.server.start();
this.client = new EnigmaClient(this, "127.0.0.1", port);
this.client.connect();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.quiltmc.enigma.gui.dialog;

import org.quiltmc.enigma.api.analysis.index.EntryIndex;
import org.quiltmc.enigma.api.analysis.index.jar.EntryIndex;
import org.quiltmc.enigma.gui.Gui;
import org.quiltmc.enigma.gui.GuiController;
import org.quiltmc.enigma.gui.config.keybind.KeyBinds;
Expand Down Expand Up @@ -200,7 +200,7 @@ public void show(boolean clear, Type... types) {

this.searchedTypes.addAll(Arrays.asList(types));

final EntryIndex entryIndex = this.gui.getController().getProject().getJarIndex().getEntryIndex();
final EntryIndex entryIndex = this.gui.getController().getProject().getJarIndex().getIndex(EntryIndex.class);

for (Type searchedType : this.searchedTypes) {
this.getCheckBox(searchedType).setSelected(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void registerDocker(Docker docker) {
public <T extends Docker> T getDocker(Class<T> clazz) {
Docker panel = this.dockers.get(clazz);
if (panel != null) {
return (T) this.dockers.get(clazz);
return (T) panel;
} else {
throw new IllegalArgumentException("no docker registered for class " + clazz);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.quiltmc.enigma.gui.util;

import com.formdev.flatlaf.extras.FlatSVGIcon;
import org.quiltmc.enigma.api.analysis.index.EntryIndex;
import org.quiltmc.enigma.api.analysis.index.jar.EntryIndex;
import org.quiltmc.enigma.gui.Gui;
import org.quiltmc.enigma.gui.config.LookAndFeel;
import org.quiltmc.enigma.api.stats.ProjectStatsResult;
Expand Down Expand Up @@ -148,7 +148,7 @@ public static Icon loadIcon(String name) {
}

public static Icon getClassIcon(Gui gui, ClassEntry entry) {
EntryIndex entryIndex = gui.getController().getProject().getJarIndex().getEntryIndex();
EntryIndex entryIndex = gui.getController().getProject().getJarIndex().getIndex(EntryIndex.class);
AccessFlags access = entryIndex.getClassAccess(entry);

if (access != null) {
Expand Down
2 changes: 1 addition & 1 deletion enigma/src/main/java/org/quiltmc/enigma/api/Enigma.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.quiltmc.enigma.api;

import org.quiltmc.enigma.api.analysis.index.JarIndex;
import org.quiltmc.enigma.api.analysis.index.jar.JarIndex;
import org.quiltmc.enigma.api.service.EnigmaService;
import org.quiltmc.enigma.api.service.EnigmaServiceContext;
import org.quiltmc.enigma.api.service.EnigmaServiceFactory;
Expand Down
39 changes: 28 additions & 11 deletions enigma/src/main/java/org/quiltmc/enigma/api/EnigmaProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import com.google.common.base.Functions;
import com.google.common.base.Preconditions;
import org.quiltmc.enigma.api.analysis.EntryReference;
import org.quiltmc.enigma.api.analysis.index.EnclosingMethodIndex;
import org.quiltmc.enigma.api.analysis.index.JarIndex;
import org.quiltmc.enigma.api.analysis.index.jar.EnclosingMethodIndex;
import org.quiltmc.enigma.api.analysis.index.jar.EntryIndex;
import org.quiltmc.enigma.api.analysis.index.jar.JarIndex;
import org.quiltmc.enigma.api.analysis.index.mapping.MappingsIndex;
import org.quiltmc.enigma.api.service.NameProposalService;
import org.quiltmc.enigma.api.service.ObfuscationTestService;
import org.quiltmc.enigma.impl.bytecode.translator.TranslationClassVisitor;
Expand Down Expand Up @@ -71,6 +73,7 @@ public class EnigmaProject {
private final Path jarPath;
private final ClassProvider classProvider;
private final JarIndex jarIndex;
private MappingsIndex mappingsIndex;
private final byte[] jarChecksum;

private EntryRemapper mapper;
Expand All @@ -84,11 +87,21 @@ public EnigmaProject(Enigma enigma, Path jarPath, ClassProvider classProvider, J
this.jarChecksum = jarChecksum;

this.mapper = EntryRemapper.empty(jarIndex);
this.mappingsIndex = MappingsIndex.empty();
}

public void setMappings(EntryTree<EntryMapping> mappings) {
/**
* Sets the current mappings of this project.
* Note that this triggers an index of the mappings, which may be expensive.
* @param mappings the new mappings
* @param progress a progress listener for indexing
*/
public void setMappings(EntryTree<EntryMapping> mappings, ProgressListener progress) {
this.mappingsIndex = MappingsIndex.empty();

if (mappings != null) {
this.mapper = EntryRemapper.mapped(this.jarIndex, mappings);
this.mappingsIndex.indexMappings(mappings, progress);
this.mapper = EntryRemapper.mapped(this.jarIndex, this.mappingsIndex, mappings);
} else {
this.mapper = EntryRemapper.empty(this.jarIndex);
}
Expand All @@ -110,6 +123,10 @@ public JarIndex getJarIndex() {
return this.jarIndex;
}

public MappingsIndex getMappingsIndex() {
return this.mappingsIndex;
}

public byte[] getJarChecksum() {
return this.jarChecksum;
}
Expand Down Expand Up @@ -155,7 +172,7 @@ public boolean isNavigable(Entry<?> obfEntry) {
return false;
}

return this.jarIndex.getEntryIndex().hasEntry(obfEntry);
return this.jarIndex.getIndex(EntryIndex.class).hasEntry(obfEntry);
}

public boolean isRenamable(Entry<?> obfEntry) {
Expand All @@ -177,7 +194,7 @@ public boolean isRenamable(Entry<?> obfEntry) {
}
}

ClassDefEntry parent = this.jarIndex.getEntryIndex().getDefinition(obfMethodEntry.getParent());
ClassDefEntry parent = this.jarIndex.getIndex(EntryIndex.class).getDefinition(obfMethodEntry.getParent());
if (parent != null && parent.isEnum()
&& ((name.equals("values") && sig.equals("()[L" + parent.getFullName() + ";"))
|| (name.equals("valueOf") && sig.equals("(Ljava/lang/String;)L" + parent.getFullName() + ";")))) {
Expand All @@ -187,7 +204,7 @@ public boolean isRenamable(Entry<?> obfEntry) {
return false;
} else if (obfEntry instanceof LocalVariableEntry localEntry && localEntry.isArgument()) {
MethodEntry method = localEntry.getParent();
ClassDefEntry parent = this.jarIndex.getEntryIndex().getDefinition(method.getParent());
ClassDefEntry parent = this.jarIndex.getIndex(EntryIndex.class).getDefinition(method.getParent());

// if this is the valueOf method of an enum class, the argument shouldn't be able to be renamed.
if (parent.isEnum() && method.getName().equals("valueOf") && method.getDesc().toString().equals("(Ljava/lang/String;)L" + parent.getFullName() + ";")) {
Expand All @@ -197,7 +214,7 @@ public boolean isRenamable(Entry<?> obfEntry) {
return false;
}

return this.jarIndex.getEntryIndex().hasEntry(obfEntry);
return this.jarIndex.getIndex(EntryIndex.class).hasEntry(obfEntry);
}

public boolean isRenamable(EntryReference<Entry<?>, Entry<?>> obfReference) {
Expand Down Expand Up @@ -236,17 +253,17 @@ public boolean hasProposedName(Entry<?> entry) {
}

public boolean isSynthetic(Entry<?> entry) {
return this.jarIndex.getEntryIndex().hasEntry(entry) && this.jarIndex.getEntryIndex().getEntryAccess(entry).isSynthetic();
return this.jarIndex.getIndex(EntryIndex.class).hasEntry(entry) && this.jarIndex.getIndex(EntryIndex.class).getEntryAccess(entry).isSynthetic();
}

public boolean isAnonymousOrLocal(ClassEntry classEntry) {
EnclosingMethodIndex enclosingMethodIndex = this.jarIndex.getEnclosingMethodIndex();
EnclosingMethodIndex enclosingMethodIndex = this.jarIndex.getIndex(EnclosingMethodIndex.class);
// Only local and anonymous classes may have the EnclosingMethod attribute
return enclosingMethodIndex.hasEnclosingMethod(classEntry);
}

public JarExport exportRemappedJar(ProgressListener progress) {
Collection<ClassEntry> classEntries = this.jarIndex.getEntryIndex().getClasses();
Collection<ClassEntry> classEntries = this.jarIndex.getIndex(EntryIndex.class).getClasses();
ClassProvider fixingClassProvider = new ObfuscationFixClassProvider(this.classProvider, this.jarIndex);

NameProposalService[] nameProposalServices = this.getEnigma().getServices().get(NameProposalService.TYPE).toArray(new NameProposalService[0]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.quiltmc.enigma.api.analysis.index;
package org.quiltmc.enigma.api.analysis.index.jar;

import com.google.common.collect.Maps;
import org.quiltmc.enigma.api.translation.representation.AccessFlags;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.quiltmc.enigma.api.analysis.index;
package org.quiltmc.enigma.api.analysis.index.jar;

import org.quiltmc.enigma.api.translation.representation.entry.ClassDefEntry;
import org.quiltmc.enigma.api.translation.representation.entry.ClassEntry;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.quiltmc.enigma.api.analysis.index;
package org.quiltmc.enigma.api.analysis.index.jar;

import org.quiltmc.enigma.api.translation.mapping.EntryMapping;
import org.quiltmc.enigma.api.translation.mapping.tree.EntryTree;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.quiltmc.enigma.api.analysis.index;
package org.quiltmc.enigma.api.analysis.index.jar;

import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
Expand Down
Loading

0 comments on commit 3ddbccd

Please sign in to comment.