diff options
| author | 2017-03-08 08:17:04 +0100 | |
|---|---|---|
| committer | 2017-03-08 08:17:04 +0100 | |
| commit | 6e464ea251cab63c776ece0b2a356f1498ffa294 (patch) | |
| tree | 5ed30c03f5ac4cd2d6877874f5ede576049954f7 /src/main/java/cuchaz/enigma/gui/GuiController.java | |
| parent | Drop unix case style and implement hashCode when equals is overrided (diff) | |
| download | enigma-fork-6e464ea251cab63c776ece0b2a356f1498ffa294.tar.gz enigma-fork-6e464ea251cab63c776ece0b2a356f1498ffa294.tar.xz enigma-fork-6e464ea251cab63c776ece0b2a356f1498ffa294.zip | |
Follow Fabric guidelines
Diffstat (limited to 'src/main/java/cuchaz/enigma/gui/GuiController.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/gui/GuiController.java | 640 |
1 files changed, 318 insertions, 322 deletions
diff --git a/src/main/java/cuchaz/enigma/gui/GuiController.java b/src/main/java/cuchaz/enigma/gui/GuiController.java index 68fd484..1b461da 100644 --- a/src/main/java/cuchaz/enigma/gui/GuiController.java +++ b/src/main/java/cuchaz/enigma/gui/GuiController.java | |||
| @@ -8,6 +8,7 @@ | |||
| 8 | * Contributors: | 8 | * Contributors: |
| 9 | * Jeff Martin - initial API and implementation | 9 | * Jeff Martin - initial API and implementation |
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | |||
| 11 | package cuchaz.enigma.gui; | 12 | package cuchaz.enigma.gui; |
| 12 | 13 | ||
| 13 | import com.google.common.collect.Lists; | 14 | import com.google.common.collect.Lists; |
| @@ -30,326 +31,321 @@ import java.util.jar.JarFile; | |||
| 30 | 31 | ||
| 31 | public class GuiController { | 32 | public class GuiController { |
| 32 | 33 | ||
| 33 | private Deobfuscator deobfuscator; | 34 | private Deobfuscator deobfuscator; |
| 34 | private Gui gui; | 35 | private Gui gui; |
| 35 | private SourceIndex index; | 36 | private SourceIndex index; |
| 36 | private ClassEntry currentObfClass; | 37 | private ClassEntry currentObfClass; |
| 37 | private boolean isDirty; | 38 | private boolean isDirty; |
| 38 | private Deque<EntryReference<Entry, Entry>> referenceStack; | 39 | private Deque<EntryReference<Entry, Entry>> referenceStack; |
| 39 | 40 | ||
| 40 | public GuiController(Gui gui) { | 41 | public GuiController(Gui gui) { |
| 41 | this.gui = gui; | 42 | this.gui = gui; |
| 42 | this.deobfuscator = null; | 43 | this.deobfuscator = null; |
| 43 | this.index = null; | 44 | this.index = null; |
| 44 | this.currentObfClass = null; | 45 | this.currentObfClass = null; |
| 45 | this.isDirty = false; | 46 | this.isDirty = false; |
| 46 | this.referenceStack = Queues.newArrayDeque(); | 47 | this.referenceStack = Queues.newArrayDeque(); |
| 47 | } | 48 | } |
| 48 | 49 | ||
| 49 | public boolean isDirty() { | 50 | public boolean isDirty() { |
| 50 | return this.isDirty; | 51 | return this.isDirty; |
| 51 | } | 52 | } |
| 52 | 53 | ||
| 53 | public void openJar(final JarFile jar) { | 54 | public void openJar(final JarFile jar) { |
| 54 | this.gui.onStartOpenJar(); | 55 | this.gui.onStartOpenJar(); |
| 55 | this.deobfuscator = new Deobfuscator(jar); | 56 | this.deobfuscator = new Deobfuscator(jar); |
| 56 | this.gui.onFinishOpenJar(this.deobfuscator.getJarName()); | 57 | this.gui.onFinishOpenJar(this.deobfuscator.getJarName()); |
| 57 | refreshClasses(); | 58 | refreshClasses(); |
| 58 | } | 59 | } |
| 59 | 60 | ||
| 60 | public void closeJar() { | 61 | public void closeJar() { |
| 61 | this.deobfuscator = null; | 62 | this.deobfuscator = null; |
| 62 | this.gui.onCloseJar(); | 63 | this.gui.onCloseJar(); |
| 63 | } | 64 | } |
| 64 | 65 | ||
| 65 | public void openEnigmaMappings(File file) throws IOException, MappingParseException { | 66 | public void openEnigmaMappings(File file) throws IOException, MappingParseException { |
| 66 | this.deobfuscator.setMappings(new MappingsEnigmaReader().read(file)); | 67 | this.deobfuscator.setMappings(new MappingsEnigmaReader().read(file)); |
| 67 | this.isDirty = false; | 68 | this.isDirty = false; |
| 68 | this.gui.setMappingsFile(file); | 69 | this.gui.setMappingsFile(file); |
| 69 | refreshClasses(); | 70 | refreshClasses(); |
| 70 | refreshCurrentClass(); | 71 | refreshCurrentClass(); |
| 71 | } | 72 | } |
| 72 | 73 | ||
| 73 | public void saveMappings(File file) throws IOException { | 74 | public void saveMappings(File file) throws IOException { |
| 74 | Mappings mappings = this.deobfuscator.getMappings(); | 75 | Mappings mappings = this.deobfuscator.getMappings(); |
| 75 | switch (mappings.getOriginMappingFormat()) | 76 | switch (mappings.getOriginMappingFormat()) { |
| 76 | { | 77 | case SRG_FILE: |
| 77 | case SRG_FILE: | 78 | saveSRGMappings(file); |
| 78 | saveSRGMappings(file); | 79 | break; |
| 79 | break; | 80 | default: |
| 80 | default: | 81 | saveEnigmaMappings(file, Mappings.FormatType.ENIGMA_FILE != mappings.getOriginMappingFormat()); |
| 81 | saveEnigmaMappings(file, Mappings.FormatType.ENIGMA_FILE != mappings.getOriginMappingFormat()); | 82 | break; |
| 82 | break; | 83 | } |
| 83 | } | 84 | |
| 84 | 85 | } | |
| 85 | } | 86 | |
| 86 | 87 | public void saveEnigmaMappings(File file, boolean isDirectoryFormat) throws IOException { | |
| 87 | public void saveEnigmaMappings(File file, boolean isDirectoryFormat) throws IOException { | 88 | this.deobfuscator.getMappings().saveEnigmaMappings(file, isDirectoryFormat); |
| 88 | this.deobfuscator.getMappings().saveEnigmaMappings(file, isDirectoryFormat); | 89 | this.isDirty = false; |
| 89 | this.isDirty = false; | 90 | } |
| 90 | } | 91 | |
| 91 | 92 | public void saveSRGMappings(File file) throws IOException { | |
| 92 | public void saveSRGMappings(File file) throws IOException { | 93 | this.deobfuscator.getMappings().saveSRGMappings(file); |
| 93 | this.deobfuscator.getMappings().saveSRGMappings(file); | 94 | this.isDirty = false; |
| 94 | this.isDirty = false; | 95 | } |
| 95 | } | 96 | |
| 96 | 97 | public void closeMappings() { | |
| 97 | public void closeMappings() { | 98 | this.deobfuscator.setMappings(null); |
| 98 | this.deobfuscator.setMappings(null); | 99 | this.gui.setMappingsFile(null); |
| 99 | this.gui.setMappingsFile(null); | 100 | refreshClasses(); |
| 100 | refreshClasses(); | 101 | refreshCurrentClass(); |
| 101 | refreshCurrentClass(); | 102 | } |
| 102 | } | 103 | |
| 103 | 104 | public void rebuildMethodNames() { | |
| 104 | public void rebuildMethodNames() { | 105 | ProgressDialog.runInThread(this.gui.getFrame(), progress -> this.deobfuscator.rebuildMethodNames(progress)); |
| 105 | ProgressDialog.runInThread(this.gui.getFrame(), progress -> this.deobfuscator.rebuildMethodNames(progress)); | 106 | } |
| 106 | } | 107 | |
| 107 | 108 | public void exportSource(final File dirOut) { | |
| 108 | public void exportSource(final File dirOut) { | 109 | ProgressDialog.runInThread(this.gui.getFrame(), progress -> this.deobfuscator.writeSources(dirOut, progress)); |
| 109 | ProgressDialog.runInThread(this.gui.getFrame(), progress -> this.deobfuscator.writeSources(dirOut, progress)); | 110 | } |
| 110 | } | 111 | |
| 111 | 112 | public void exportJar(final File fileOut) { | |
| 112 | public void exportJar(final File fileOut) { | 113 | ProgressDialog.runInThread(this.gui.getFrame(), progress -> this.deobfuscator.writeJar(fileOut, progress)); |
| 113 | ProgressDialog.runInThread(this.gui.getFrame(), progress -> this.deobfuscator.writeJar(fileOut, progress)); | 114 | } |
| 114 | } | 115 | |
| 115 | 116 | public Token getToken(int pos) { | |
| 116 | public Token getToken(int pos) { | 117 | if (this.index == null) { |
| 117 | if (this.index == null) { | 118 | return null; |
| 118 | return null; | 119 | } |
| 119 | } | 120 | return this.index.getReferenceToken(pos); |
| 120 | return this.index.getReferenceToken(pos); | 121 | } |
| 121 | } | 122 | |
| 122 | 123 | public EntryReference<Entry, Entry> getDeobfReference(Token token) { | |
| 123 | public EntryReference<Entry, Entry> getDeobfReference(Token token) { | 124 | if (this.index == null) { |
| 124 | if (this.index == null) { | 125 | return null; |
| 125 | return null; | 126 | } |
| 126 | } | 127 | return this.index.getDeobfReference(token); |
| 127 | return this.index.getDeobfReference(token); | 128 | } |
| 128 | } | 129 | |
| 129 | 130 | public ReadableToken getReadableToken(Token token) { | |
| 130 | public ReadableToken getReadableToken(Token token) { | 131 | if (this.index == null) { |
| 131 | if (this.index == null) { | 132 | return null; |
| 132 | return null; | 133 | } |
| 133 | } | 134 | return new ReadableToken( |
| 134 | return new ReadableToken( | 135 | this.index.getLineNumber(token.start), |
| 135 | this.index.getLineNumber(token.start), | 136 | this.index.getColumnNumber(token.start), |
| 136 | this.index.getColumnNumber(token.start), | 137 | this.index.getColumnNumber(token.end) |
| 137 | this.index.getColumnNumber(token.end) | 138 | ); |
| 138 | ); | 139 | } |
| 139 | } | 140 | |
| 140 | 141 | public boolean entryHasDeobfuscatedName(Entry deobfEntry) { | |
| 141 | public boolean entryHasDeobfuscatedName(Entry deobfEntry) { | 142 | return this.deobfuscator.hasDeobfuscatedName(this.deobfuscator.obfuscateEntry(deobfEntry)); |
| 142 | return this.deobfuscator.hasDeobfuscatedName(this.deobfuscator.obfuscateEntry(deobfEntry)); | 143 | } |
| 143 | } | 144 | |
| 144 | 145 | public boolean entryIsInJar(Entry deobfEntry) { | |
| 145 | public boolean entryIsInJar(Entry deobfEntry) { | 146 | return this.deobfuscator.isObfuscatedIdentifier(this.deobfuscator.obfuscateEntry(deobfEntry)); |
| 146 | return this.deobfuscator.isObfuscatedIdentifier(this.deobfuscator.obfuscateEntry(deobfEntry)); | 147 | } |
| 147 | } | 148 | |
| 148 | 149 | public boolean referenceIsRenameable(EntryReference<Entry, Entry> deobfReference) { | |
| 149 | public boolean referenceIsRenameable(EntryReference<Entry, Entry> deobfReference) { | 150 | return this.deobfuscator.isRenameable(this.deobfuscator.obfuscateReference(deobfReference), true); |
| 150 | return this.deobfuscator.isRenameable(this.deobfuscator.obfuscateReference(deobfReference), true); | 151 | } |
| 151 | } | 152 | |
| 152 | 153 | public ClassInheritanceTreeNode getClassInheritance(ClassEntry deobfClassEntry) { | |
| 153 | public ClassInheritanceTreeNode getClassInheritance(ClassEntry deobfClassEntry) { | 154 | ClassEntry obfClassEntry = this.deobfuscator.obfuscateEntry(deobfClassEntry); |
| 154 | ClassEntry obfClassEntry = this.deobfuscator.obfuscateEntry(deobfClassEntry); | 155 | ClassInheritanceTreeNode rootNode = this.deobfuscator.getJarIndex().getClassInheritance(this.deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfClassEntry); |
| 155 | ClassInheritanceTreeNode rootNode = this.deobfuscator.getJarIndex().getClassInheritance(this.deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfClassEntry); | 156 | return ClassInheritanceTreeNode.findNode(rootNode, obfClassEntry); |
| 156 | return ClassInheritanceTreeNode.findNode(rootNode, obfClassEntry); | 157 | } |
| 157 | } | 158 | |
| 158 | 159 | public ClassImplementationsTreeNode getClassImplementations(ClassEntry deobfClassEntry) { | |
| 159 | public ClassImplementationsTreeNode getClassImplementations(ClassEntry deobfClassEntry) { | 160 | ClassEntry obfClassEntry = this.deobfuscator.obfuscateEntry(deobfClassEntry); |
| 160 | ClassEntry obfClassEntry = this.deobfuscator.obfuscateEntry(deobfClassEntry); | 161 | return this.deobfuscator.getJarIndex().getClassImplementations(this.deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfClassEntry); |
| 161 | return this.deobfuscator.getJarIndex().getClassImplementations(this.deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfClassEntry); | 162 | } |
| 162 | } | 163 | |
| 163 | 164 | public MethodInheritanceTreeNode getMethodInheritance(MethodEntry deobfMethodEntry) { | |
| 164 | public MethodInheritanceTreeNode getMethodInheritance(MethodEntry deobfMethodEntry) { | 165 | MethodEntry obfMethodEntry = this.deobfuscator.obfuscateEntry(deobfMethodEntry); |
| 165 | MethodEntry obfMethodEntry = this.deobfuscator.obfuscateEntry(deobfMethodEntry); | 166 | MethodInheritanceTreeNode rootNode = this.deobfuscator.getJarIndex().getMethodInheritance(this.deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfMethodEntry); |
| 166 | MethodInheritanceTreeNode rootNode = this.deobfuscator.getJarIndex().getMethodInheritance(this.deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfMethodEntry); | 167 | return MethodInheritanceTreeNode.findNode(rootNode, obfMethodEntry); |
| 167 | return MethodInheritanceTreeNode.findNode(rootNode, obfMethodEntry); | 168 | } |
| 168 | } | 169 | |
| 169 | 170 | public MethodImplementationsTreeNode getMethodImplementations(MethodEntry deobfMethodEntry) { | |
| 170 | public MethodImplementationsTreeNode getMethodImplementations(MethodEntry deobfMethodEntry) { | 171 | MethodEntry obfMethodEntry = this.deobfuscator.obfuscateEntry(deobfMethodEntry); |
| 171 | MethodEntry obfMethodEntry = this.deobfuscator.obfuscateEntry(deobfMethodEntry); | 172 | List<MethodImplementationsTreeNode> rootNodes = this.deobfuscator.getJarIndex().getMethodImplementations(this.deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfMethodEntry); |
| 172 | List<MethodImplementationsTreeNode> rootNodes = this.deobfuscator.getJarIndex().getMethodImplementations(this.deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfMethodEntry); | 173 | if (rootNodes.isEmpty()) { |
| 173 | if (rootNodes.isEmpty()) { | 174 | return null; |
| 174 | return null; | 175 | } |
| 175 | } | 176 | if (rootNodes.size() > 1) { |
| 176 | if (rootNodes.size() > 1) { | 177 | System.err.println("WARNING: Method " + deobfMethodEntry + " implements multiple interfaces. Only showing first one."); |
| 177 | System.err.println("WARNING: Method " + deobfMethodEntry + " implements multiple interfaces. Only showing first one."); | 178 | } |
| 178 | } | 179 | return MethodImplementationsTreeNode.findNode(rootNodes.get(0), obfMethodEntry); |
| 179 | return MethodImplementationsTreeNode.findNode(rootNodes.get(0), obfMethodEntry); | 180 | } |
| 180 | } | 181 | |
| 181 | 182 | public FieldReferenceTreeNode getFieldReferences(FieldEntry deobfFieldEntry) { | |
| 182 | public FieldReferenceTreeNode getFieldReferences(FieldEntry deobfFieldEntry) { | 183 | FieldEntry obfFieldEntry = this.deobfuscator.obfuscateEntry(deobfFieldEntry); |
| 183 | FieldEntry obfFieldEntry = this.deobfuscator.obfuscateEntry(deobfFieldEntry); | 184 | FieldReferenceTreeNode rootNode = new FieldReferenceTreeNode(this.deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfFieldEntry); |
| 184 | FieldReferenceTreeNode rootNode = new FieldReferenceTreeNode(this.deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfFieldEntry); | 185 | rootNode.load(this.deobfuscator.getJarIndex(), true); |
| 185 | rootNode.load(this.deobfuscator.getJarIndex(), true); | 186 | return rootNode; |
| 186 | return rootNode; | 187 | } |
| 187 | } | 188 | |
| 188 | 189 | public BehaviorReferenceTreeNode getMethodReferences(BehaviorEntry deobfBehaviorEntry) { | |
| 189 | public BehaviorReferenceTreeNode getMethodReferences(BehaviorEntry deobfBehaviorEntry) { | 190 | BehaviorEntry obfBehaviorEntry = this.deobfuscator.obfuscateEntry(deobfBehaviorEntry); |
| 190 | BehaviorEntry obfBehaviorEntry = this.deobfuscator.obfuscateEntry(deobfBehaviorEntry); | 191 | BehaviorReferenceTreeNode rootNode = new BehaviorReferenceTreeNode(this.deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfBehaviorEntry); |
| 191 | BehaviorReferenceTreeNode rootNode = new BehaviorReferenceTreeNode(this.deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfBehaviorEntry); | 192 | rootNode.load(this.deobfuscator.getJarIndex(), true); |
| 192 | rootNode.load(this.deobfuscator.getJarIndex(), true); | 193 | return rootNode; |
| 193 | return rootNode; | 194 | } |
| 194 | } | 195 | |
| 195 | 196 | public void rename(EntryReference<Entry, Entry> deobfReference, String newName) { | |
| 196 | public void rename(EntryReference<Entry, Entry> deobfReference, String newName) { | 197 | rename(deobfReference, newName, true, true); |
| 197 | rename(deobfReference, newName, true, true); | 198 | } |
| 198 | } | 199 | |
| 199 | 200 | public void rename(EntryReference<Entry, Entry> deobfReference, String newName, boolean refreshClassTree, boolean clearTranslationCache) { | |
| 200 | public void rename(EntryReference<Entry, Entry> deobfReference, String newName, boolean refreshClassTree, boolean clearTranslationCache) | 201 | EntryReference<Entry, Entry> obfReference = this.deobfuscator.obfuscateReference(deobfReference); |
| 201 | { | 202 | this.deobfuscator.rename(obfReference.getNameableEntry(), newName, clearTranslationCache); |
| 202 | EntryReference<Entry, Entry> obfReference = this.deobfuscator.obfuscateReference(deobfReference); | 203 | this.isDirty = true; |
| 203 | this.deobfuscator.rename(obfReference.getNameableEntry(), newName, clearTranslationCache); | 204 | |
| 204 | this.isDirty = true; | 205 | if (refreshClassTree && deobfReference.entry instanceof ClassEntry && !((ClassEntry) deobfReference.entry).isInnerClass()) |
| 205 | 206 | this.gui.moveClassTree(deobfReference, newName); | |
| 206 | if (refreshClassTree && deobfReference.entry instanceof ClassEntry && !((ClassEntry) deobfReference.entry).isInnerClass()) | 207 | refreshCurrentClass(obfReference); |
| 207 | this.gui.moveClassTree(deobfReference, newName); | 208 | |
| 208 | refreshCurrentClass(obfReference); | 209 | } |
| 209 | 210 | ||
| 210 | } | 211 | public void removeMapping(EntryReference<Entry, Entry> deobfReference) { |
| 211 | 212 | EntryReference<Entry, Entry> obfReference = this.deobfuscator.obfuscateReference(deobfReference); | |
| 212 | public void removeMapping(EntryReference<Entry, Entry> deobfReference) { | 213 | this.deobfuscator.removeMapping(obfReference.getNameableEntry()); |
| 213 | EntryReference<Entry, Entry> obfReference = this.deobfuscator.obfuscateReference(deobfReference); | 214 | this.isDirty = true; |
| 214 | this.deobfuscator.removeMapping(obfReference.getNameableEntry()); | 215 | if (deobfReference.entry instanceof ClassEntry) |
| 215 | this.isDirty = true; | 216 | this.gui.moveClassTree(deobfReference, obfReference.entry.getName(), false, true); |
| 216 | if (deobfReference.entry instanceof ClassEntry) | 217 | refreshCurrentClass(obfReference); |
| 217 | this.gui.moveClassTree(deobfReference, obfReference.entry.getName(), false, true); | 218 | } |
| 218 | refreshCurrentClass(obfReference); | 219 | |
| 219 | } | 220 | public void markAsDeobfuscated(EntryReference<Entry, Entry> deobfReference) { |
| 220 | 221 | EntryReference<Entry, Entry> obfReference = this.deobfuscator.obfuscateReference(deobfReference); | |
| 221 | public void markAsDeobfuscated(EntryReference<Entry, Entry> deobfReference) { | 222 | this.deobfuscator.markAsDeobfuscated(obfReference.getNameableEntry()); |
| 222 | EntryReference<Entry, Entry> obfReference = this.deobfuscator.obfuscateReference(deobfReference); | 223 | this.isDirty = true; |
| 223 | this.deobfuscator.markAsDeobfuscated(obfReference.getNameableEntry()); | 224 | if (deobfReference.entry instanceof ClassEntry && !((ClassEntry) deobfReference.entry).isInnerClass()) |
| 224 | this.isDirty = true; | 225 | this.gui.moveClassTree(deobfReference, obfReference.entry.getName(), true, false); |
| 225 | if (deobfReference.entry instanceof ClassEntry && !((ClassEntry) deobfReference.entry).isInnerClass()) | 226 | refreshCurrentClass(obfReference); |
| 226 | this.gui.moveClassTree(deobfReference, obfReference.entry.getName(), true, false); | 227 | } |
| 227 | refreshCurrentClass(obfReference); | 228 | |
| 228 | } | 229 | public void openDeclaration(Entry deobfEntry) { |
| 229 | 230 | if (deobfEntry == null) { | |
| 230 | public void openDeclaration(Entry deobfEntry) { | 231 | throw new IllegalArgumentException("Entry cannot be null!"); |
| 231 | if (deobfEntry == null) { | 232 | } |
| 232 | throw new IllegalArgumentException("Entry cannot be null!"); | 233 | openReference(new EntryReference<>(deobfEntry, deobfEntry.getName())); |
| 233 | } | 234 | } |
| 234 | openReference(new EntryReference<>(deobfEntry, deobfEntry.getName())); | 235 | |
| 235 | } | 236 | public void openReference(EntryReference<Entry, Entry> deobfReference) { |
| 236 | 237 | if (deobfReference == null) { | |
| 237 | public void openReference(EntryReference<Entry, Entry> deobfReference) { | 238 | throw new IllegalArgumentException("Reference cannot be null!"); |
| 238 | if (deobfReference == null) { | 239 | } |
| 239 | throw new IllegalArgumentException("Reference cannot be null!"); | 240 | |
| 240 | } | 241 | // get the reference target class |
| 241 | 242 | EntryReference<Entry, Entry> obfReference = this.deobfuscator.obfuscateReference(deobfReference); | |
| 242 | // get the reference target class | 243 | ClassEntry obfClassEntry = obfReference.getLocationClassEntry().getOutermostClassEntry(); |
| 243 | EntryReference<Entry, Entry> obfReference = this.deobfuscator.obfuscateReference(deobfReference); | 244 | if (!this.deobfuscator.isObfuscatedIdentifier(obfClassEntry)) { |
| 244 | ClassEntry obfClassEntry = obfReference.getLocationClassEntry().getOutermostClassEntry(); | 245 | throw new IllegalArgumentException("Obfuscated class " + obfClassEntry + " was not found in the jar!"); |
| 245 | if (!this.deobfuscator.isObfuscatedIdentifier(obfClassEntry)) { | 246 | } |
| 246 | throw new IllegalArgumentException("Obfuscated class " + obfClassEntry + " was not found in the jar!"); | 247 | if (this.currentObfClass == null || !this.currentObfClass.equals(obfClassEntry)) { |
| 247 | } | 248 | // deobfuscate the class, then navigate to the reference |
| 248 | if (this.currentObfClass == null || !this.currentObfClass.equals(obfClassEntry)) { | 249 | this.currentObfClass = obfClassEntry; |
| 249 | // deobfuscate the class, then navigate to the reference | 250 | deobfuscate(this.currentObfClass, obfReference); |
| 250 | this.currentObfClass = obfClassEntry; | 251 | } else { |
| 251 | deobfuscate(this.currentObfClass, obfReference); | 252 | showReference(obfReference); |
| 252 | } else { | 253 | } |
| 253 | showReference(obfReference); | 254 | } |
| 254 | } | 255 | |
| 255 | } | 256 | private void showReference(EntryReference<Entry, Entry> obfReference) { |
| 256 | 257 | EntryReference<Entry, Entry> deobfReference = this.deobfuscator.deobfuscateReference(obfReference); | |
| 257 | private void showReference(EntryReference<Entry, Entry> obfReference) { | 258 | Collection<Token> tokens = this.index.getReferenceTokens(deobfReference); |
| 258 | EntryReference<Entry, Entry> deobfReference = this.deobfuscator.deobfuscateReference(obfReference); | 259 | if (tokens.isEmpty()) { |
| 259 | Collection<Token> tokens = this.index.getReferenceTokens(deobfReference); | 260 | // DEBUG |
| 260 | if (tokens.isEmpty()) { | 261 | System.err.println(String.format("WARNING: no tokens found for %s in %s", deobfReference, this.currentObfClass)); |
| 261 | // DEBUG | 262 | } else { |
| 262 | System.err.println(String.format("WARNING: no tokens found for %s in %s", deobfReference, this.currentObfClass)); | 263 | this.gui.showTokens(tokens); |
| 263 | } else { | 264 | } |
| 264 | this.gui.showTokens(tokens); | 265 | } |
| 265 | } | 266 | |
| 266 | } | 267 | public void savePreviousReference(EntryReference<Entry, Entry> deobfReference) { |
| 267 | 268 | this.referenceStack.push(this.deobfuscator.obfuscateReference(deobfReference)); | |
| 268 | public void savePreviousReference(EntryReference<Entry, Entry> deobfReference) { | 269 | } |
| 269 | this.referenceStack.push(this.deobfuscator.obfuscateReference(deobfReference)); | 270 | |
| 270 | } | 271 | public void openPreviousReference() { |
| 271 | 272 | if (hasPreviousLocation()) { | |
| 272 | public void openPreviousReference() { | 273 | openReference(this.deobfuscator.deobfuscateReference(this.referenceStack.pop())); |
| 273 | if (hasPreviousLocation()) { | 274 | } |
| 274 | openReference(this.deobfuscator.deobfuscateReference(this.referenceStack.pop())); | 275 | } |
| 275 | } | 276 | |
| 276 | } | 277 | public boolean hasPreviousLocation() { |
| 277 | 278 | return !this.referenceStack.isEmpty(); | |
| 278 | public boolean hasPreviousLocation() { | 279 | } |
| 279 | return !this.referenceStack.isEmpty(); | 280 | |
| 280 | } | 281 | private void refreshClasses() { |
| 281 | 282 | List<ClassEntry> obfClasses = Lists.newArrayList(); | |
| 282 | private void refreshClasses() { | 283 | List<ClassEntry> deobfClasses = Lists.newArrayList(); |
| 283 | List<ClassEntry> obfClasses = Lists.newArrayList(); | 284 | this.deobfuscator.getSeparatedClasses(obfClasses, deobfClasses); |
| 284 | List<ClassEntry> deobfClasses = Lists.newArrayList(); | 285 | this.gui.setObfClasses(obfClasses); |
| 285 | this.deobfuscator.getSeparatedClasses(obfClasses, deobfClasses); | 286 | this.gui.setDeobfClasses(deobfClasses); |
| 286 | this.gui.setObfClasses(obfClasses); | 287 | } |
| 287 | this.gui.setDeobfClasses(deobfClasses); | 288 | |
| 288 | } | 289 | public void refreshCurrentClass() { |
| 289 | 290 | refreshCurrentClass(null); | |
| 290 | public void refreshCurrentClass() { | 291 | } |
| 291 | refreshCurrentClass(null); | 292 | |
| 292 | } | 293 | private void refreshCurrentClass(EntryReference<Entry, Entry> obfReference) { |
| 293 | 294 | if (this.currentObfClass != null) { | |
| 294 | private void refreshCurrentClass(EntryReference<Entry, Entry> obfReference) { | 295 | deobfuscate(this.currentObfClass, obfReference); |
| 295 | if (this.currentObfClass != null) { | 296 | } |
| 296 | deobfuscate(this.currentObfClass, obfReference); | 297 | } |
| 297 | } | 298 | |
| 298 | } | 299 | private void deobfuscate(final ClassEntry classEntry, final EntryReference<Entry, Entry> obfReference) { |
| 299 | 300 | ||
| 300 | private void deobfuscate(final ClassEntry classEntry, final EntryReference<Entry, Entry> obfReference) { | 301 | this.gui.setSource("(deobfuscating...)"); |
| 301 | 302 | ||
| 302 | this.gui.setSource("(deobfuscating...)"); | 303 | // run the deobfuscator in a separate thread so we don't block the GUI event queue |
| 303 | 304 | new Thread(() -> | |
| 304 | // run the deobfuscator in a separate thread so we don't block the GUI event queue | 305 | { |
| 305 | new Thread(() -> | 306 | // decompile,deobfuscate the bytecode |
| 306 | { | 307 | CompilationUnit sourceTree = deobfuscator.getSourceTree(classEntry.getClassName()); |
| 307 | // decompile,deobfuscate the bytecode | 308 | if (sourceTree == null) { |
| 308 | CompilationUnit sourceTree = deobfuscator.getSourceTree(classEntry.getClassName()); | 309 | // decompilation of this class is not supported |
| 309 | if (sourceTree == null) { | 310 | gui.setSource("Unable to find class: " + classEntry); |
| 310 | // decompilation of this class is not supported | 311 | return; |
| 311 | gui.setSource("Unable to find class: " + classEntry); | 312 | } |
| 312 | return; | 313 | String source = deobfuscator.getSource(sourceTree); |
| 313 | } | 314 | index = deobfuscator.getSourceIndex(sourceTree, source); |
| 314 | String source = deobfuscator.getSource(sourceTree); | 315 | gui.setSource(index.getSource()); |
| 315 | index = deobfuscator.getSourceIndex(sourceTree, source); | 316 | if (obfReference != null) { |
| 316 | gui.setSource(index.getSource()); | 317 | showReference(obfReference); |
| 317 | if (obfReference != null) { | 318 | } |
| 318 | showReference(obfReference); | 319 | |
| 319 | } | 320 | // set the highlighted tokens |
| 320 | 321 | List<Token> obfuscatedTokens = Lists.newArrayList(); | |
| 321 | // set the highlighted tokens | 322 | List<Token> deobfuscatedTokens = Lists.newArrayList(); |
| 322 | List<Token> obfuscatedTokens = Lists.newArrayList(); | 323 | List<Token> otherTokens = Lists.newArrayList(); |
| 323 | List<Token> deobfuscatedTokens = Lists.newArrayList(); | 324 | for (Token token : index.referenceTokens()) { |
| 324 | List<Token> otherTokens = Lists.newArrayList(); | 325 | EntryReference<Entry, Entry> reference = index.getDeobfReference(token); |
| 325 | for (Token token : index.referenceTokens()) { | 326 | if (referenceIsRenameable(reference)) { |
| 326 | EntryReference<Entry, Entry> reference = index.getDeobfReference(token); | 327 | if (entryHasDeobfuscatedName(reference.getNameableEntry())) { |
| 327 | if (referenceIsRenameable(reference)) { | 328 | deobfuscatedTokens.add(token); |
| 328 | if (entryHasDeobfuscatedName(reference.getNameableEntry())) { | 329 | } else { |
| 329 | deobfuscatedTokens.add(token); | 330 | obfuscatedTokens.add(token); |
| 330 | } else { | 331 | } |
| 331 | obfuscatedTokens.add(token); | 332 | } else { |
| 332 | } | 333 | otherTokens.add(token); |
| 333 | } else { | 334 | } |
| 334 | otherTokens.add(token); | 335 | } |
| 335 | } | 336 | gui.setHighlightedTokens(obfuscatedTokens, deobfuscatedTokens, otherTokens); |
| 336 | } | 337 | }).start(); |
| 337 | gui.setHighlightedTokens(obfuscatedTokens, deobfuscatedTokens, otherTokens); | 338 | } |
| 338 | }).start(); | 339 | |
| 339 | } | 340 | public Deobfuscator getDeobfuscator() { |
| 340 | 341 | return deobfuscator; | |
| 341 | public Deobfuscator getDeobfuscator() | 342 | } |
| 342 | { | 343 | |
| 343 | return deobfuscator; | 344 | public void modifierChange(ItemEvent event) { |
| 344 | } | 345 | if (event.getStateChange() == ItemEvent.SELECTED) { |
| 345 | 346 | deobfuscator.changeModifier(gui.reference.entry, (Mappings.EntryModifier) event.getItem()); | |
| 346 | public void modifierChange(ItemEvent event) | 347 | this.isDirty = true; |
| 347 | { | 348 | refreshCurrentClass(); |
| 348 | if (event.getStateChange() == ItemEvent.SELECTED) | 349 | } |
| 349 | { | 350 | } |
| 350 | deobfuscator.changeModifier(gui.reference.entry, (Mappings.EntryModifier) event.getItem()); | ||
| 351 | this.isDirty = true; | ||
| 352 | refreshCurrentClass(); | ||
| 353 | } | ||
| 354 | } | ||
| 355 | } | 351 | } |