diff options
Diffstat (limited to 'src/main')
| -rw-r--r-- | src/main/java/cuchaz/enigma/Deobfuscator.java | 14 | ||||
| -rw-r--r-- | src/main/java/cuchaz/enigma/api/EnigmaPlugin.java | 20 | ||||
| -rw-r--r-- | src/main/java/cuchaz/enigma/gui/DecompiledClassSource.java | 28 |
3 files changed, 27 insertions, 35 deletions
diff --git a/src/main/java/cuchaz/enigma/Deobfuscator.java b/src/main/java/cuchaz/enigma/Deobfuscator.java index b4736d8..9060c1f 100644 --- a/src/main/java/cuchaz/enigma/Deobfuscator.java +++ b/src/main/java/cuchaz/enigma/Deobfuscator.java | |||
| @@ -13,6 +13,7 @@ package cuchaz.enigma; | |||
| 13 | 13 | ||
| 14 | import com.google.common.base.Functions; | 14 | import com.google.common.base.Functions; |
| 15 | import com.google.common.base.Stopwatch; | 15 | import com.google.common.base.Stopwatch; |
| 16 | import com.google.common.collect.Streams; | ||
| 16 | import com.strobel.assembler.metadata.ITypeLoader; | 17 | import com.strobel.assembler.metadata.ITypeLoader; |
| 17 | import com.strobel.assembler.metadata.MetadataSystem; | 18 | import com.strobel.assembler.metadata.MetadataSystem; |
| 18 | import com.strobel.assembler.metadata.TypeDefinition; | 19 | import com.strobel.assembler.metadata.TypeDefinition; |
| @@ -54,6 +55,7 @@ import java.util.jar.JarEntry; | |||
| 54 | import java.util.jar.JarFile; | 55 | import java.util.jar.JarFile; |
| 55 | import java.util.jar.JarOutputStream; | 56 | import java.util.jar.JarOutputStream; |
| 56 | import java.util.stream.Collectors; | 57 | import java.util.stream.Collectors; |
| 58 | import java.util.stream.Stream; | ||
| 57 | 59 | ||
| 58 | public class Deobfuscator { | 60 | public class Deobfuscator { |
| 59 | 61 | ||
| @@ -73,10 +75,10 @@ public class Deobfuscator { | |||
| 73 | this.jarIndex = JarIndex.empty(); | 75 | this.jarIndex = JarIndex.empty(); |
| 74 | this.jarIndex.indexJar(this.parsedJar, listener); | 76 | this.jarIndex.indexJar(this.parsedJar, listener); |
| 75 | 77 | ||
| 76 | listener.accept("Initializing plugins..."); | 78 | getPlugins().forEach(plugin -> { |
| 77 | for (EnigmaPlugin plugin : getPlugins()) { | 79 | listener.accept("Initializing plugin '" + plugin.getClass().getSimpleName() + "'"); |
| 78 | plugin.onClassesLoaded(parsedJar.getClassDataMap(), parsedJar::getClassNode); | 80 | plugin.indexJar(parsedJar, jarIndex); |
| 79 | } | 81 | }); |
| 80 | 82 | ||
| 81 | this.indexTreeBuilder = new IndexTreeBuilder(jarIndex); | 83 | this.indexTreeBuilder = new IndexTreeBuilder(jarIndex); |
| 82 | 84 | ||
| @@ -105,8 +107,8 @@ public class Deobfuscator { | |||
| 105 | }); | 107 | }); |
| 106 | } | 108 | } |
| 107 | 109 | ||
| 108 | public ServiceLoader<EnigmaPlugin> getPlugins() { | 110 | public Stream<EnigmaPlugin> getPlugins() { |
| 109 | return plugins; | 111 | return Streams.stream(plugins); |
| 110 | } | 112 | } |
| 111 | 113 | ||
| 112 | public ParsedJar getJar() { | 114 | public ParsedJar getJar() { |
diff --git a/src/main/java/cuchaz/enigma/api/EnigmaPlugin.java b/src/main/java/cuchaz/enigma/api/EnigmaPlugin.java index 3efe0dc..a5ec9c4 100644 --- a/src/main/java/cuchaz/enigma/api/EnigmaPlugin.java +++ b/src/main/java/cuchaz/enigma/api/EnigmaPlugin.java | |||
| @@ -1,18 +1,14 @@ | |||
| 1 | package cuchaz.enigma.api; | 1 | package cuchaz.enigma.api; |
| 2 | 2 | ||
| 3 | import org.objectweb.asm.tree.ClassNode; | 3 | import cuchaz.enigma.analysis.ParsedJar; |
| 4 | import cuchaz.enigma.analysis.index.JarIndex; | ||
| 5 | import cuchaz.enigma.translation.mapping.EntryRemapper; | ||
| 6 | import cuchaz.enigma.translation.representation.entry.Entry; | ||
| 4 | 7 | ||
| 5 | import javax.annotation.Nullable; | 8 | import java.util.Optional; |
| 6 | import java.util.Map; | ||
| 7 | import java.util.function.Function; | ||
| 8 | 9 | ||
| 9 | public abstract class EnigmaPlugin { | 10 | public interface EnigmaPlugin { |
| 10 | public void onClassesLoaded(Map<String, byte[]> classData, Function<String, ClassNode> classNodeGetter) { | 11 | void indexJar(ParsedJar jar, JarIndex index); |
| 11 | 12 | ||
| 12 | } | 13 | Optional<String> proposeName(Entry<?> obfEntry, EntryRemapper remapper); |
| 13 | |||
| 14 | @Nullable | ||
| 15 | public String proposeFieldName(String owner, String name, String desc) { | ||
| 16 | return null; | ||
| 17 | } | ||
| 18 | } | 14 | } |
diff --git a/src/main/java/cuchaz/enigma/gui/DecompiledClassSource.java b/src/main/java/cuchaz/enigma/gui/DecompiledClassSource.java index 93643ab..1e96a06 100644 --- a/src/main/java/cuchaz/enigma/gui/DecompiledClassSource.java +++ b/src/main/java/cuchaz/enigma/gui/DecompiledClassSource.java | |||
| @@ -4,18 +4,17 @@ import cuchaz.enigma.Deobfuscator; | |||
| 4 | import cuchaz.enigma.analysis.EntryReference; | 4 | import cuchaz.enigma.analysis.EntryReference; |
| 5 | import cuchaz.enigma.analysis.SourceIndex; | 5 | import cuchaz.enigma.analysis.SourceIndex; |
| 6 | import cuchaz.enigma.analysis.Token; | 6 | import cuchaz.enigma.analysis.Token; |
| 7 | import cuchaz.enigma.api.EnigmaPlugin; | ||
| 8 | import cuchaz.enigma.gui.highlight.TokenHighlightType; | 7 | import cuchaz.enigma.gui.highlight.TokenHighlightType; |
| 9 | import cuchaz.enigma.translation.LocalNameGenerator; | 8 | import cuchaz.enigma.translation.LocalNameGenerator; |
| 10 | import cuchaz.enigma.translation.Translator; | 9 | import cuchaz.enigma.translation.Translator; |
| 11 | import cuchaz.enigma.translation.representation.TypeDescriptor; | 10 | import cuchaz.enigma.translation.representation.TypeDescriptor; |
| 12 | import cuchaz.enigma.translation.representation.entry.ClassEntry; | 11 | import cuchaz.enigma.translation.representation.entry.ClassEntry; |
| 13 | import cuchaz.enigma.translation.representation.entry.Entry; | 12 | import cuchaz.enigma.translation.representation.entry.Entry; |
| 14 | import cuchaz.enigma.translation.representation.entry.FieldEntry; | ||
| 15 | import cuchaz.enigma.translation.representation.entry.LocalVariableDefEntry; | 13 | import cuchaz.enigma.translation.representation.entry.LocalVariableDefEntry; |
| 16 | 14 | ||
| 17 | import javax.annotation.Nullable; | 15 | import javax.annotation.Nullable; |
| 18 | import java.util.*; | 16 | import java.util.*; |
| 17 | import java.util.stream.Stream; | ||
| 19 | 18 | ||
| 20 | public class DecompiledClassSource { | 19 | public class DecompiledClassSource { |
| 21 | private final ClassEntry classEntry; | 20 | private final ClassEntry classEntry; |
| @@ -55,10 +54,10 @@ public class DecompiledClassSource { | |||
| 55 | highlightToken(movedToken, TokenHighlightType.DEOBFUSCATED); | 54 | highlightToken(movedToken, TokenHighlightType.DEOBFUSCATED); |
| 56 | return translatedEntry.getSourceRemapName(); | 55 | return translatedEntry.getSourceRemapName(); |
| 57 | } else { | 56 | } else { |
| 58 | String proposedName = proposeName(deobfuscator, entry); | 57 | Optional<String> proposedName = proposeName(deobfuscator, entry); |
| 59 | if (proposedName != null) { | 58 | if (proposedName.isPresent()) { |
| 60 | highlightToken(movedToken, TokenHighlightType.PROPOSED); | 59 | highlightToken(movedToken, TokenHighlightType.PROPOSED); |
| 61 | return proposedName; | 60 | return proposedName.get(); |
| 62 | } | 61 | } |
| 63 | 62 | ||
| 64 | highlightToken(movedToken, TokenHighlightType.OBFUSCATED); | 63 | highlightToken(movedToken, TokenHighlightType.OBFUSCATED); |
| @@ -73,18 +72,13 @@ public class DecompiledClassSource { | |||
| 73 | return null; | 72 | return null; |
| 74 | } | 73 | } |
| 75 | 74 | ||
| 76 | @Nullable | 75 | private Optional<String> proposeName(Deobfuscator deobfuscator, Entry<?> entry) { |
| 77 | private String proposeName(Deobfuscator deobfuscator, Entry<?> entry) { | 76 | Stream<String> proposals = deobfuscator.getPlugins() |
| 78 | if (entry instanceof FieldEntry) { | 77 | .map(plugin -> plugin.proposeName(entry, deobfuscator.getMapper())) |
| 79 | for (EnigmaPlugin plugin : deobfuscator.getPlugins()) { | 78 | .filter(Optional::isPresent) |
| 80 | String owner = entry.getContainingClass().getFullName(); | 79 | .map(Optional::get); |
| 81 | String proposal = plugin.proposeFieldName(owner, entry.getName(), ((FieldEntry) entry).getDesc().toString()); | 80 | |
| 82 | if (proposal != null) { | 81 | return proposals.findFirst(); |
| 83 | return proposal; | ||
| 84 | } | ||
| 85 | } | ||
| 86 | } | ||
| 87 | return null; | ||
| 88 | } | 82 | } |
| 89 | 83 | ||
| 90 | @Nullable | 84 | @Nullable |