diff options
| author | 2022-03-30 17:44:58 +0100 | |
|---|---|---|
| committer | 2022-03-30 17:44:58 +0100 | |
| commit | 64537ba10cf6627ed944cb66b22019c698f705d8 (patch) | |
| tree | ea6acb7e83e5f0902c454895952780878953579d /enigma | |
| parent | feat(i18n): update Chinese(Simplified) translation (#441) (diff) | |
| download | enigma-fork-64537ba10cf6627ed944cb66b22019c698f705d8.tar.gz enigma-fork-64537ba10cf6627ed944cb66b22019c698f705d8.tar.xz enigma-fork-64537ba10cf6627ed944cb66b22019c698f705d8.zip | |
Add readonly bytecode view. (#443)
Diffstat (limited to 'enigma')
5 files changed, 94 insertions, 0 deletions
diff --git a/enigma/src/main/java/cuchaz/enigma/analysis/BuiltinPlugin.java b/enigma/src/main/java/cuchaz/enigma/analysis/BuiltinPlugin.java index 989464d..013c52f 100644 --- a/enigma/src/main/java/cuchaz/enigma/analysis/BuiltinPlugin.java +++ b/enigma/src/main/java/cuchaz/enigma/analysis/BuiltinPlugin.java | |||
| @@ -57,6 +57,7 @@ public final class BuiltinPlugin implements EnigmaPlugin { | |||
| 57 | private void registerDecompilerServices(EnigmaPluginContext ctx) { | 57 | private void registerDecompilerServices(EnigmaPluginContext ctx) { |
| 58 | ctx.registerService("enigma:procyon", DecompilerService.TYPE, ctx1 -> Decompilers.PROCYON); | 58 | ctx.registerService("enigma:procyon", DecompilerService.TYPE, ctx1 -> Decompilers.PROCYON); |
| 59 | ctx.registerService("enigma:cfr", DecompilerService.TYPE, ctx1 -> Decompilers.CFR); | 59 | ctx.registerService("enigma:cfr", DecompilerService.TYPE, ctx1 -> Decompilers.CFR); |
| 60 | ctx.registerService("enigma:bytecode", DecompilerService.TYPE, ctx1 -> Decompilers.BYTECODE); | ||
| 60 | } | 61 | } |
| 61 | 62 | ||
| 62 | private static final class EnumFieldNameFindingVisitor extends ClassVisitor { | 63 | private static final class EnumFieldNameFindingVisitor extends ClassVisitor { |
diff --git a/enigma/src/main/java/cuchaz/enigma/source/Decompilers.java b/enigma/src/main/java/cuchaz/enigma/source/Decompilers.java index 7d154a6..643ea7a 100644 --- a/enigma/src/main/java/cuchaz/enigma/source/Decompilers.java +++ b/enigma/src/main/java/cuchaz/enigma/source/Decompilers.java | |||
| @@ -1,9 +1,11 @@ | |||
| 1 | package cuchaz.enigma.source; | 1 | package cuchaz.enigma.source; |
| 2 | 2 | ||
| 3 | import cuchaz.enigma.source.bytecode.BytecodeDecompiler; | ||
| 3 | import cuchaz.enigma.source.cfr.CfrDecompiler; | 4 | import cuchaz.enigma.source.cfr.CfrDecompiler; |
| 4 | import cuchaz.enigma.source.procyon.ProcyonDecompiler; | 5 | import cuchaz.enigma.source.procyon.ProcyonDecompiler; |
| 5 | 6 | ||
| 6 | public class Decompilers { | 7 | public class Decompilers { |
| 7 | public static final DecompilerService PROCYON = ProcyonDecompiler::new; | 8 | public static final DecompilerService PROCYON = ProcyonDecompiler::new; |
| 8 | public static final DecompilerService CFR = CfrDecompiler::new; | 9 | public static final DecompilerService CFR = CfrDecompiler::new; |
| 10 | public static final DecompilerService BYTECODE = BytecodeDecompiler::new; | ||
| 9 | } | 11 | } |
diff --git a/enigma/src/main/java/cuchaz/enigma/source/bytecode/BytecodeDecompiler.java b/enigma/src/main/java/cuchaz/enigma/source/bytecode/BytecodeDecompiler.java new file mode 100644 index 0000000..97d2969 --- /dev/null +++ b/enigma/src/main/java/cuchaz/enigma/source/bytecode/BytecodeDecompiler.java | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | package cuchaz.enigma.source.bytecode; | ||
| 2 | |||
| 3 | import cuchaz.enigma.classprovider.ClassProvider; | ||
| 4 | import cuchaz.enigma.source.Decompiler; | ||
| 5 | import cuchaz.enigma.source.Source; | ||
| 6 | import cuchaz.enigma.source.SourceSettings; | ||
| 7 | import cuchaz.enigma.translation.mapping.EntryRemapper; | ||
| 8 | import org.checkerframework.checker.nullness.qual.Nullable; | ||
| 9 | |||
| 10 | public class BytecodeDecompiler implements Decompiler { | ||
| 11 | private final ClassProvider classProvider; | ||
| 12 | |||
| 13 | public BytecodeDecompiler(ClassProvider classProvider, SourceSettings settings) { | ||
| 14 | this.classProvider = classProvider; | ||
| 15 | } | ||
| 16 | |||
| 17 | @Override | ||
| 18 | public Source getSource(String className, @Nullable EntryRemapper remapper) { | ||
| 19 | return new BytecodeSource(classProvider.get(className), remapper); | ||
| 20 | } | ||
| 21 | } | ||
diff --git a/enigma/src/main/java/cuchaz/enigma/source/bytecode/BytecodeSource.java b/enigma/src/main/java/cuchaz/enigma/source/bytecode/BytecodeSource.java new file mode 100644 index 0000000..4364b40 --- /dev/null +++ b/enigma/src/main/java/cuchaz/enigma/source/bytecode/BytecodeSource.java | |||
| @@ -0,0 +1,56 @@ | |||
| 1 | package cuchaz.enigma.source.bytecode; | ||
| 2 | |||
| 3 | import cuchaz.enigma.Enigma; | ||
| 4 | import cuchaz.enigma.bytecode.translators.TranslationClassVisitor; | ||
| 5 | import cuchaz.enigma.source.Source; | ||
| 6 | import cuchaz.enigma.source.SourceIndex; | ||
| 7 | import cuchaz.enigma.translation.mapping.EntryRemapper; | ||
| 8 | import org.objectweb.asm.tree.ClassNode; | ||
| 9 | import org.objectweb.asm.util.TraceClassVisitor; | ||
| 10 | |||
| 11 | import java.io.PrintWriter; | ||
| 12 | import java.io.StringWriter; | ||
| 13 | |||
| 14 | public class BytecodeSource implements Source { | ||
| 15 | private final ClassNode classNode; | ||
| 16 | private final EntryRemapper remapper; | ||
| 17 | |||
| 18 | public BytecodeSource(ClassNode classNode, EntryRemapper remapper) { | ||
| 19 | this.classNode = classNode; | ||
| 20 | this.remapper = remapper; | ||
| 21 | } | ||
| 22 | |||
| 23 | @Override | ||
| 24 | public String asString() { | ||
| 25 | return index().getSource(); | ||
| 26 | } | ||
| 27 | |||
| 28 | @Override | ||
| 29 | public Source withJavadocs(EntryRemapper remapper) { | ||
| 30 | return new BytecodeSource(classNode, remapper); | ||
| 31 | } | ||
| 32 | |||
| 33 | @Override | ||
| 34 | public SourceIndex index() { | ||
| 35 | SourceIndex index = new SourceIndex(); | ||
| 36 | |||
| 37 | EnigmaTextifier textifier = new EnigmaTextifier(index); | ||
| 38 | StringWriter out = new StringWriter(); | ||
| 39 | PrintWriter writer = new PrintWriter(out); | ||
| 40 | |||
| 41 | TraceClassVisitor traceClassVisitor = new TraceClassVisitor(null, textifier, writer); | ||
| 42 | |||
| 43 | ClassNode node = this.classNode; | ||
| 44 | |||
| 45 | if (remapper != null) { | ||
| 46 | ClassNode translatedNode = new ClassNode(); | ||
| 47 | node.accept(new TranslationClassVisitor(remapper.getDeobfuscator(), Enigma.ASM_VERSION, translatedNode)); | ||
| 48 | node = translatedNode; | ||
| 49 | } | ||
| 50 | |||
| 51 | node.accept(traceClassVisitor); | ||
| 52 | index.setSource(out.toString()); | ||
| 53 | |||
| 54 | return index; | ||
| 55 | } | ||
| 56 | } | ||
diff --git a/enigma/src/main/java/cuchaz/enigma/source/bytecode/EnigmaTextifier.java b/enigma/src/main/java/cuchaz/enigma/source/bytecode/EnigmaTextifier.java new file mode 100644 index 0000000..2f3fcf2 --- /dev/null +++ b/enigma/src/main/java/cuchaz/enigma/source/bytecode/EnigmaTextifier.java | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | package cuchaz.enigma.source.bytecode; | ||
| 2 | |||
| 3 | import cuchaz.enigma.Enigma; | ||
| 4 | import cuchaz.enigma.source.SourceIndex; | ||
| 5 | import org.objectweb.asm.util.Textifier; | ||
| 6 | |||
| 7 | public class EnigmaTextifier extends Textifier { | ||
| 8 | private final SourceIndex sourceIndex; | ||
| 9 | |||
| 10 | public EnigmaTextifier(SourceIndex sourceIndex) { | ||
| 11 | super(Enigma.ASM_VERSION); | ||
| 12 | this.sourceIndex = sourceIndex; | ||
| 13 | } | ||
| 14 | } | ||