diff options
Diffstat (limited to 'enigma/src/main/java')
5 files changed, 105 insertions, 0 deletions
diff --git a/enigma/src/main/java/cuchaz/enigma/EnigmaProject.java b/enigma/src/main/java/cuchaz/enigma/EnigmaProject.java index 96ad433..1e4afa2 100644 --- a/enigma/src/main/java/cuchaz/enigma/EnigmaProject.java +++ b/enigma/src/main/java/cuchaz/enigma/EnigmaProject.java | |||
| @@ -6,6 +6,7 @@ import java.io.PrintWriter; | |||
| 6 | import java.io.StringWriter; | 6 | import java.io.StringWriter; |
| 7 | import java.nio.file.Files; | 7 | import java.nio.file.Files; |
| 8 | import java.nio.file.Path; | 8 | import java.nio.file.Path; |
| 9 | import java.util.ArrayList; | ||
| 9 | import java.util.Collection; | 10 | import java.util.Collection; |
| 10 | import java.util.List; | 11 | import java.util.List; |
| 11 | import java.util.Map; | 12 | import java.util.Map; |
| @@ -17,11 +18,14 @@ import java.util.jar.JarOutputStream; | |||
| 17 | import java.util.stream.Collectors; | 18 | import java.util.stream.Collectors; |
| 18 | import java.util.stream.Stream; | 19 | import java.util.stream.Stream; |
| 19 | 20 | ||
| 21 | import org.jetbrains.annotations.Nullable; | ||
| 20 | import org.objectweb.asm.ClassWriter; | 22 | import org.objectweb.asm.ClassWriter; |
| 21 | import org.objectweb.asm.tree.ClassNode; | 23 | import org.objectweb.asm.tree.ClassNode; |
| 22 | 24 | ||
| 23 | import cuchaz.enigma.analysis.EntryReference; | 25 | import cuchaz.enigma.analysis.EntryReference; |
| 24 | import cuchaz.enigma.analysis.index.JarIndex; | 26 | import cuchaz.enigma.analysis.index.JarIndex; |
| 27 | import cuchaz.enigma.api.DataInvalidationEvent; | ||
| 28 | import cuchaz.enigma.api.DataInvalidationListener; | ||
| 25 | import cuchaz.enigma.api.service.NameProposalService; | 29 | import cuchaz.enigma.api.service.NameProposalService; |
| 26 | import cuchaz.enigma.api.service.ObfuscationTestService; | 30 | import cuchaz.enigma.api.service.ObfuscationTestService; |
| 27 | import cuchaz.enigma.api.view.ProjectView; | 31 | import cuchaz.enigma.api.view.ProjectView; |
| @@ -57,6 +61,8 @@ public class EnigmaProject implements ProjectView { | |||
| 57 | 61 | ||
| 58 | private EntryRemapper mapper; | 62 | private EntryRemapper mapper; |
| 59 | 63 | ||
| 64 | private final List<DataInvalidationListener> dataInvalidationListeners = new ArrayList<>(); | ||
| 65 | |||
| 60 | public EnigmaProject(Enigma enigma, List<Path> jarPaths, ClassProvider classProvider, JarIndex jarIndex, byte[] jarChecksum) { | 66 | public EnigmaProject(Enigma enigma, List<Path> jarPaths, ClassProvider classProvider, JarIndex jarIndex, byte[] jarChecksum) { |
| 61 | if (jarChecksum.length != 20) { | 67 | if (jarChecksum.length != 20) { |
| 62 | throw new IllegalArgumentException(); | 68 | throw new IllegalArgumentException(); |
| @@ -334,6 +340,29 @@ public class EnigmaProject implements ProjectView { | |||
| 334 | return (T) mapper.extendedDeobfuscate((Translatable) entry).getValue(); | 340 | return (T) mapper.extendedDeobfuscate((Translatable) entry).getValue(); |
| 335 | } | 341 | } |
| 336 | 342 | ||
| 343 | @Override | ||
| 344 | public void addDataInvalidationListener(DataInvalidationListener listener) { | ||
| 345 | dataInvalidationListeners.add(listener); | ||
| 346 | } | ||
| 347 | |||
| 348 | @Override | ||
| 349 | public void invalidateData(@Nullable Collection<String> classes, DataInvalidationEvent.InvalidationType type) { | ||
| 350 | DataInvalidationEvent event = new DataInvalidationEvent() { | ||
| 351 | @Override | ||
| 352 | @Nullable | ||
| 353 | public Collection<String> getClasses() { | ||
| 354 | return classes; | ||
| 355 | } | ||
| 356 | |||
| 357 | @Override | ||
| 358 | public InvalidationType getType() { | ||
| 359 | return type; | ||
| 360 | } | ||
| 361 | }; | ||
| 362 | |||
| 363 | dataInvalidationListeners.forEach(listener -> listener.onDataInvalidated(event)); | ||
| 364 | } | ||
| 365 | |||
| 337 | public static final class SourceExport { | 366 | public static final class SourceExport { |
| 338 | public final Collection<ClassSource> decompiled; | 367 | public final Collection<ClassSource> decompiled; |
| 339 | 368 | ||
diff --git a/enigma/src/main/java/cuchaz/enigma/api/DataInvalidationEvent.java b/enigma/src/main/java/cuchaz/enigma/api/DataInvalidationEvent.java new file mode 100644 index 0000000..812ad39 --- /dev/null +++ b/enigma/src/main/java/cuchaz/enigma/api/DataInvalidationEvent.java | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | package cuchaz.enigma.api; | ||
| 2 | |||
| 3 | import java.util.Collection; | ||
| 4 | |||
| 5 | import org.jetbrains.annotations.Nullable; | ||
| 6 | |||
| 7 | public interface DataInvalidationEvent { | ||
| 8 | /** | ||
| 9 | * The classes for which the invalidation applies, or {@code null} if the invalidation applies to all classes. | ||
| 10 | */ | ||
| 11 | @Nullable | ||
| 12 | Collection<String> getClasses(); | ||
| 13 | |||
| 14 | InvalidationType getType(); | ||
| 15 | |||
| 16 | enum InvalidationType { | ||
| 17 | /** | ||
| 18 | * Only mappings are being invalidated. | ||
| 19 | */ | ||
| 20 | MAPPINGS, | ||
| 21 | /** | ||
| 22 | * Javadocs are being invalidated. This also implies {@link #MAPPINGS}. | ||
| 23 | */ | ||
| 24 | JAVADOC, | ||
| 25 | /** | ||
| 26 | * Context passed to the decompiler, such as the bytecode input or other parameters, is being invalidated. This | ||
| 27 | * also implies {@link #JAVADOC} and {@link #MAPPINGS}. | ||
| 28 | */ | ||
| 29 | DECOMPILE, | ||
| 30 | } | ||
| 31 | } | ||
diff --git a/enigma/src/main/java/cuchaz/enigma/api/DataInvalidationListener.java b/enigma/src/main/java/cuchaz/enigma/api/DataInvalidationListener.java new file mode 100644 index 0000000..a07b109 --- /dev/null +++ b/enigma/src/main/java/cuchaz/enigma/api/DataInvalidationListener.java | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | package cuchaz.enigma.api; | ||
| 2 | |||
| 3 | @FunctionalInterface | ||
| 4 | public interface DataInvalidationListener { | ||
| 5 | void onDataInvalidated(DataInvalidationEvent event); | ||
| 6 | } | ||
diff --git a/enigma/src/main/java/cuchaz/enigma/api/view/ProjectView.java b/enigma/src/main/java/cuchaz/enigma/api/view/ProjectView.java index e07645a..eae776b 100644 --- a/enigma/src/main/java/cuchaz/enigma/api/view/ProjectView.java +++ b/enigma/src/main/java/cuchaz/enigma/api/view/ProjectView.java | |||
| @@ -1,7 +1,26 @@ | |||
| 1 | package cuchaz.enigma.api.view; | 1 | package cuchaz.enigma.api.view; |
| 2 | 2 | ||
| 3 | import java.util.Collection; | ||
| 4 | import java.util.List; | ||
| 5 | |||
| 6 | import org.jetbrains.annotations.Nullable; | ||
| 7 | |||
| 8 | import cuchaz.enigma.api.DataInvalidationEvent; | ||
| 9 | import cuchaz.enigma.api.DataInvalidationListener; | ||
| 3 | import cuchaz.enigma.api.view.entry.EntryView; | 10 | import cuchaz.enigma.api.view.entry.EntryView; |
| 4 | 11 | ||
| 5 | public interface ProjectView { | 12 | public interface ProjectView { |
| 6 | <T extends EntryView> T deobfuscate(T entry); | 13 | <T extends EntryView> T deobfuscate(T entry); |
| 14 | |||
| 15 | void addDataInvalidationListener(DataInvalidationListener listener); | ||
| 16 | |||
| 17 | default void invalidateData(DataInvalidationEvent.InvalidationType type) { | ||
| 18 | invalidateData((Collection<String>) null, type); | ||
| 19 | } | ||
| 20 | |||
| 21 | default void invalidateData(String className, DataInvalidationEvent.InvalidationType type) { | ||
| 22 | invalidateData(List.of(className), type); | ||
| 23 | } | ||
| 24 | |||
| 25 | void invalidateData(@Nullable Collection<String> classes, DataInvalidationEvent.InvalidationType type); | ||
| 7 | } | 26 | } |
diff --git a/enigma/src/main/java/cuchaz/enigma/classhandle/ClassHandleProvider.java b/enigma/src/main/java/cuchaz/enigma/classhandle/ClassHandleProvider.java index f4bbb1d..f441bf4 100644 --- a/enigma/src/main/java/cuchaz/enigma/classhandle/ClassHandleProvider.java +++ b/enigma/src/main/java/cuchaz/enigma/classhandle/ClassHandleProvider.java | |||
| @@ -163,6 +163,26 @@ public final class ClassHandleProvider { | |||
| 163 | }); | 163 | }); |
| 164 | } | 164 | } |
| 165 | 165 | ||
| 166 | public void invalidate() { | ||
| 167 | withLock(lock.readLock(), () -> { | ||
| 168 | handles.values().forEach(Entry::invalidate); | ||
| 169 | }); | ||
| 170 | } | ||
| 171 | |||
| 172 | public void invalidate(ClassEntry entry) { | ||
| 173 | withLock(lock.readLock(), () -> { | ||
| 174 | Entry e = handles.get(entry); | ||
| 175 | |||
| 176 | if (e != null) { | ||
| 177 | e.invalidate(); | ||
| 178 | } | ||
| 179 | |||
| 180 | if (entry.isInnerClass()) { | ||
| 181 | this.invalidate(entry.getOuterClass()); | ||
| 182 | } | ||
| 183 | }); | ||
| 184 | } | ||
| 185 | |||
| 166 | private void deleteEntry(Entry entry) { | 186 | private void deleteEntry(Entry entry) { |
| 167 | withLock(lock.writeLock(), () -> { | 187 | withLock(lock.writeLock(), () -> { |
| 168 | handles.remove(entry.entry); | 188 | handles.remove(entry.entry); |