diff options
| author | 2019-02-19 19:16:55 +0200 | |
|---|---|---|
| committer | 2019-02-19 19:16:55 +0200 | |
| commit | d23e4d934c9b020adcbde411a64bbef7549f3020 (patch) | |
| tree | bbd61d5fb08d589ede58d0949e33255b95f62bcc /src | |
| parent | Match token navigation reference resolution to match source index (diff) | |
| download | enigma-d23e4d934c9b020adcbde411a64bbef7549f3020.tar.gz enigma-d23e4d934c9b020adcbde411a64bbef7549f3020.tar.xz enigma-d23e4d934c9b020adcbde411a64bbef7549f3020.zip | |
Write stacktrace to editor when decompilation throws an exception
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/java/cuchaz/enigma/gui/DecompiledClassSource.java | 18 | ||||
| -rw-r--r-- | src/main/java/cuchaz/enigma/gui/GuiController.java | 35 |
2 files changed, 32 insertions, 21 deletions
diff --git a/src/main/java/cuchaz/enigma/gui/DecompiledClassSource.java b/src/main/java/cuchaz/enigma/gui/DecompiledClassSource.java index 0ac41b3e..93643ab4 100644 --- a/src/main/java/cuchaz/enigma/gui/DecompiledClassSource.java +++ b/src/main/java/cuchaz/enigma/gui/DecompiledClassSource.java | |||
| @@ -19,30 +19,32 @@ import java.util.*; | |||
| 19 | 19 | ||
| 20 | public class DecompiledClassSource { | 20 | public class DecompiledClassSource { |
| 21 | private final ClassEntry classEntry; | 21 | private final ClassEntry classEntry; |
| 22 | private final Deobfuscator deobfuscator; | ||
| 23 | 22 | ||
| 24 | private final SourceIndex obfuscatedIndex; | 23 | private final SourceIndex obfuscatedIndex; |
| 25 | private SourceIndex remappedIndex; | 24 | private SourceIndex remappedIndex; |
| 26 | 25 | ||
| 27 | private final Map<TokenHighlightType, Collection<Token>> highlightedTokens = new EnumMap<>(TokenHighlightType.class); | 26 | private final Map<TokenHighlightType, Collection<Token>> highlightedTokens = new EnumMap<>(TokenHighlightType.class); |
| 28 | 27 | ||
| 29 | public DecompiledClassSource(ClassEntry classEntry, Deobfuscator deobfuscator, SourceIndex index) { | 28 | public DecompiledClassSource(ClassEntry classEntry, SourceIndex index) { |
| 30 | this.classEntry = classEntry; | 29 | this.classEntry = classEntry; |
| 31 | this.deobfuscator = deobfuscator; | ||
| 32 | this.obfuscatedIndex = index; | 30 | this.obfuscatedIndex = index; |
| 33 | this.remappedIndex = index; | 31 | this.remappedIndex = index; |
| 34 | } | 32 | } |
| 35 | 33 | ||
| 36 | public void remapSource(Translator translator) { | 34 | public static DecompiledClassSource text(ClassEntry classEntry, String text) { |
| 35 | return new DecompiledClassSource(classEntry, new SourceIndex(text)); | ||
| 36 | } | ||
| 37 | |||
| 38 | public void remapSource(Deobfuscator deobfuscator, Translator translator) { | ||
| 37 | highlightedTokens.clear(); | 39 | highlightedTokens.clear(); |
| 38 | 40 | ||
| 39 | SourceRemapper remapper = new SourceRemapper(obfuscatedIndex.getSource(), obfuscatedIndex.referenceTokens()); | 41 | SourceRemapper remapper = new SourceRemapper(obfuscatedIndex.getSource(), obfuscatedIndex.referenceTokens()); |
| 40 | 42 | ||
| 41 | SourceRemapper.Result remapResult = remapper.remap((token, movedToken) -> remapToken(token, movedToken, translator)); | 43 | SourceRemapper.Result remapResult = remapper.remap((token, movedToken) -> remapToken(deobfuscator, token, movedToken, translator)); |
| 42 | remappedIndex = obfuscatedIndex.remapTo(remapResult); | 44 | remappedIndex = obfuscatedIndex.remapTo(remapResult); |
| 43 | } | 45 | } |
| 44 | 46 | ||
| 45 | private String remapToken(Token token, Token movedToken, Translator translator) { | 47 | private String remapToken(Deobfuscator deobfuscator, Token token, Token movedToken, Translator translator) { |
| 46 | EntryReference<Entry<?>, Entry<?>> reference = obfuscatedIndex.getReference(token); | 48 | EntryReference<Entry<?>, Entry<?>> reference = obfuscatedIndex.getReference(token); |
| 47 | 49 | ||
| 48 | Entry<?> entry = reference.getNameableEntry(); | 50 | Entry<?> entry = reference.getNameableEntry(); |
| @@ -53,7 +55,7 @@ public class DecompiledClassSource { | |||
| 53 | highlightToken(movedToken, TokenHighlightType.DEOBFUSCATED); | 55 | highlightToken(movedToken, TokenHighlightType.DEOBFUSCATED); |
| 54 | return translatedEntry.getSourceRemapName(); | 56 | return translatedEntry.getSourceRemapName(); |
| 55 | } else { | 57 | } else { |
| 56 | String proposedName = proposeName(entry); | 58 | String proposedName = proposeName(deobfuscator, entry); |
| 57 | if (proposedName != null) { | 59 | if (proposedName != null) { |
| 58 | highlightToken(movedToken, TokenHighlightType.PROPOSED); | 60 | highlightToken(movedToken, TokenHighlightType.PROPOSED); |
| 59 | return proposedName; | 61 | return proposedName; |
| @@ -72,7 +74,7 @@ public class DecompiledClassSource { | |||
| 72 | } | 74 | } |
| 73 | 75 | ||
| 74 | @Nullable | 76 | @Nullable |
| 75 | private String proposeName(Entry<?> entry) { | 77 | private String proposeName(Deobfuscator deobfuscator, Entry<?> entry) { |
| 76 | if (entry instanceof FieldEntry) { | 78 | if (entry instanceof FieldEntry) { |
| 77 | for (EnigmaPlugin plugin : deobfuscator.getPlugins()) { | 79 | for (EnigmaPlugin plugin : deobfuscator.getPlugins()) { |
| 78 | String owner = entry.getContainingClass().getFullName(); | 80 | String owner = entry.getContainingClass().getFullName(); |
diff --git a/src/main/java/cuchaz/enigma/gui/GuiController.java b/src/main/java/cuchaz/enigma/gui/GuiController.java index 357d812b..a8ff0d03 100644 --- a/src/main/java/cuchaz/enigma/gui/GuiController.java +++ b/src/main/java/cuchaz/enigma/gui/GuiController.java | |||
| @@ -35,6 +35,8 @@ import javax.annotation.Nullable; | |||
| 35 | import java.awt.event.ItemEvent; | 35 | import java.awt.event.ItemEvent; |
| 36 | import java.io.File; | 36 | import java.io.File; |
| 37 | import java.io.IOException; | 37 | import java.io.IOException; |
| 38 | import java.io.PrintWriter; | ||
| 39 | import java.io.StringWriter; | ||
| 38 | import java.nio.file.Path; | 40 | import java.nio.file.Path; |
| 39 | import java.util.Collection; | 41 | import java.util.Collection; |
| 40 | import java.util.Deque; | 42 | import java.util.Deque; |
| @@ -320,7 +322,7 @@ public class GuiController { | |||
| 320 | DECOMPILER_SERVICE.submit(() -> { | 322 | DECOMPILER_SERVICE.submit(() -> { |
| 321 | try { | 323 | try { |
| 322 | if (requiresDecompile) { | 324 | if (requiresDecompile) { |
| 323 | decompileSource(targetClass, deobfuscator.getObfSourceProvider()); | 325 | currentSource = decompileSource(targetClass, deobfuscator.getObfSourceProvider()); |
| 324 | } | 326 | } |
| 325 | 327 | ||
| 326 | remapSource(deobfuscator.getMapper().getDeobfuscator()); | 328 | remapSource(deobfuscator.getMapper().getDeobfuscator()); |
| @@ -332,21 +334,28 @@ public class GuiController { | |||
| 332 | }); | 334 | }); |
| 333 | } | 335 | } |
| 334 | 336 | ||
| 335 | private void decompileSource(ClassEntry targetClass, SourceProvider sourceProvider) { | 337 | private DecompiledClassSource decompileSource(ClassEntry targetClass, SourceProvider sourceProvider) { |
| 336 | CompilationUnit sourceTree = sourceProvider.getSources(targetClass.getFullName()); | 338 | try { |
| 337 | if (sourceTree == null) { | 339 | CompilationUnit sourceTree = sourceProvider.getSources(targetClass.getFullName()); |
| 338 | gui.setEditorText("Unable to find class: " + targetClass); | 340 | if (sourceTree == null) { |
| 339 | return; | 341 | gui.setEditorText("Unable to find class: " + targetClass); |
| 340 | } | 342 | return DecompiledClassSource.text(targetClass, "Unable to find class"); |
| 343 | } | ||
| 341 | 344 | ||
| 342 | DropImportAstTransform.INSTANCE.run(sourceTree); | 345 | DropImportAstTransform.INSTANCE.run(sourceTree); |
| 343 | 346 | ||
| 344 | String sourceString = sourceProvider.writeSourceToString(sourceTree); | 347 | String sourceString = sourceProvider.writeSourceToString(sourceTree); |
| 345 | 348 | ||
| 346 | SourceIndex index = SourceIndex.buildIndex(sourceString, sourceTree, true); | 349 | SourceIndex index = SourceIndex.buildIndex(sourceString, sourceTree, true); |
| 347 | index.resolveReferences(deobfuscator.getMapper().getObfResolver()); | 350 | index.resolveReferences(deobfuscator.getMapper().getObfResolver()); |
| 348 | 351 | ||
| 349 | currentSource = new DecompiledClassSource(targetClass, deobfuscator, index); | 352 | return new DecompiledClassSource(targetClass, index); |
| 353 | } catch (Exception e) { | ||
| 354 | StringWriter traceWriter = new StringWriter(); | ||
| 355 | e.printStackTrace(new PrintWriter(traceWriter)); | ||
| 356 | |||
| 357 | return DecompiledClassSource.text(targetClass, traceWriter.toString()); | ||
| 358 | } | ||
| 350 | } | 359 | } |
| 351 | 360 | ||
| 352 | private void remapSource(Translator translator) { | 361 | private void remapSource(Translator translator) { |
| @@ -354,7 +363,7 @@ public class GuiController { | |||
| 354 | return; | 363 | return; |
| 355 | } | 364 | } |
| 356 | 365 | ||
| 357 | currentSource.remapSource(translator); | 366 | currentSource.remapSource(deobfuscator, translator); |
| 358 | 367 | ||
| 359 | gui.setEditorTheme(Config.getInstance().lookAndFeel); | 368 | gui.setEditorTheme(Config.getInstance().lookAndFeel); |
| 360 | gui.setSource(currentSource); | 369 | gui.setSource(currentSource); |