From 74edc74c2c7b3236f00bf92499bb884837673b7d Mon Sep 17 00:00:00 2001 From: lclc98 Date: Sat, 2 Jul 2016 20:13:13 +1000 Subject: Reformatting code --- src/main/java/cuchaz/enigma/gui/GuiController.java | 212 +++++++++------------ 1 file changed, 91 insertions(+), 121 deletions(-) (limited to 'src/main/java/cuchaz/enigma/gui/GuiController.java') diff --git a/src/main/java/cuchaz/enigma/gui/GuiController.java b/src/main/java/cuchaz/enigma/gui/GuiController.java index a6a2ec5..868e0d4 100644 --- a/src/main/java/cuchaz/enigma/gui/GuiController.java +++ b/src/main/java/cuchaz/enigma/gui/GuiController.java @@ -24,162 +24,138 @@ import java.util.List; import java.util.jar.JarFile; import cuchaz.enigma.Deobfuscator; -import cuchaz.enigma.Deobfuscator.ProgressListener; import cuchaz.enigma.analysis.*; -import cuchaz.enigma.gui.ProgressDialog.ProgressRunnable; import cuchaz.enigma.mapping.*; public class GuiController { - private Deobfuscator m_deobfuscator; - private Gui m_gui; - private SourceIndex m_index; - private ClassEntry m_currentObfClass; - private boolean m_isDirty; - private Deque> m_referenceStack; + private Deobfuscator deobfuscator; + private Gui gui; + private SourceIndex index; + private ClassEntry currentObfClass; + private boolean isDirty; + private Deque> referenceStack; public GuiController(Gui gui) { - m_gui = gui; - m_deobfuscator = null; - m_index = null; - m_currentObfClass = null; - m_isDirty = false; - m_referenceStack = Queues.newArrayDeque(); + this.gui = gui; + this.deobfuscator = null; + this.index = null; + this.currentObfClass = null; + this.isDirty = false; + this.referenceStack = Queues.newArrayDeque(); } public boolean isDirty() { - return m_isDirty; + return this.isDirty; } public void openJar(final JarFile jar) throws IOException { - m_gui.onStartOpenJar(); - m_deobfuscator = new Deobfuscator(jar); - m_gui.onFinishOpenJar(m_deobfuscator.getJarName()); + this.gui.onStartOpenJar(); + this.deobfuscator = new Deobfuscator(jar); + this.gui.onFinishOpenJar(this.deobfuscator.getJarName()); refreshClasses(); } public void closeJar() { - m_deobfuscator = null; - m_gui.onCloseJar(); + this.deobfuscator = null; + this.gui.onCloseJar(); } public void openOldMappings(File file) throws IOException, MappingParseException { FileReader in = new FileReader(file); - m_deobfuscator.setMappings(new MappingsReaderOld().read(in)); + this.deobfuscator.setMappings(new MappingsReaderOld().read(in)); in.close(); - m_isDirty = false; - m_gui.setMappingsFile(file); + this.isDirty = false; + this.gui.setMappingsFile(file); refreshClasses(); refreshCurrentClass(); } public void openMappings(File file) throws IOException, MappingParseException { - m_deobfuscator.setMappings(new MappingsReader().read(file)); - m_isDirty = false; - m_gui.setMappingsFile(file); + this.deobfuscator.setMappings(new MappingsReader().read(file)); + this.isDirty = false; + this.gui.setMappingsFile(file); refreshClasses(); refreshCurrentClass(); } public void saveMappings(File file) throws IOException { - new MappingsWriter().write(file, m_deobfuscator.getMappings()); - m_isDirty = false; + new MappingsWriter().write(file, this.deobfuscator.getMappings()); + this.isDirty = false; } public void closeMappings() { - m_deobfuscator.setMappings(null); - m_gui.setMappingsFile(null); + this.deobfuscator.setMappings(null); + this.gui.setMappingsFile(null); refreshClasses(); refreshCurrentClass(); } public void exportSource(final File dirOut) { - ProgressDialog.runInThread(m_gui.getFrame(), new ProgressRunnable() { - @Override - public void run(ProgressListener progress) throws Exception { - m_deobfuscator.writeSources(dirOut, progress); - } - }); + ProgressDialog.runInThread(this.gui.getFrame(), progress -> this.deobfuscator.writeSources(dirOut, progress)); } public void exportJar(final File fileOut) { - ProgressDialog.runInThread(m_gui.getFrame(), new ProgressRunnable() { - @Override - public void run(ProgressListener progress) { - m_deobfuscator.writeJar(fileOut, progress); - } - }); + ProgressDialog.runInThread(this.gui.getFrame(), progress -> this.deobfuscator.writeJar(fileOut, progress)); } public Token getToken(int pos) { - if (m_index == null) { + if (this.index == null) { return null; } - return m_index.getReferenceToken(pos); + return this.index.getReferenceToken(pos); } public EntryReference getDeobfReference(Token token) { - if (m_index == null) { + if (this.index == null) { return null; } - return m_index.getDeobfReference(token); + return this.index.getDeobfReference(token); } public ReadableToken getReadableToken(Token token) { - if (m_index == null) { + if (this.index == null) { return null; } return new ReadableToken( - m_index.getLineNumber(token.start), - m_index.getColumnNumber(token.start), - m_index.getColumnNumber(token.end) + this.index.getLineNumber(token.start), + this.index.getColumnNumber(token.start), + this.index.getColumnNumber(token.end) ); } public boolean entryHasDeobfuscatedName(Entry deobfEntry) { - return m_deobfuscator.hasDeobfuscatedName(m_deobfuscator.obfuscateEntry(deobfEntry)); + return this.deobfuscator.hasDeobfuscatedName(this.deobfuscator.obfuscateEntry(deobfEntry)); } public boolean entryIsInJar(Entry deobfEntry) { - return m_deobfuscator.isObfuscatedIdentifier(m_deobfuscator.obfuscateEntry(deobfEntry)); + return this.deobfuscator.isObfuscatedIdentifier(this.deobfuscator.obfuscateEntry(deobfEntry)); } public boolean referenceIsRenameable(EntryReference deobfReference) { - return m_deobfuscator.isRenameable(m_deobfuscator.obfuscateReference(deobfReference)); + return this.deobfuscator.isRenameable(this.deobfuscator.obfuscateReference(deobfReference)); } public ClassInheritanceTreeNode getClassInheritance(ClassEntry deobfClassEntry) { - ClassEntry obfClassEntry = m_deobfuscator.obfuscateEntry(deobfClassEntry); - ClassInheritanceTreeNode rootNode = m_deobfuscator.getJarIndex().getClassInheritance( - m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating), - obfClassEntry - ); + ClassEntry obfClassEntry = this.deobfuscator.obfuscateEntry(deobfClassEntry); + ClassInheritanceTreeNode rootNode = this.deobfuscator.getJarIndex().getClassInheritance(this.deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfClassEntry); return ClassInheritanceTreeNode.findNode(rootNode, obfClassEntry); } public ClassImplementationsTreeNode getClassImplementations(ClassEntry deobfClassEntry) { - ClassEntry obfClassEntry = m_deobfuscator.obfuscateEntry(deobfClassEntry); - return m_deobfuscator.getJarIndex().getClassImplementations( - m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating), - obfClassEntry - ); + ClassEntry obfClassEntry = this.deobfuscator.obfuscateEntry(deobfClassEntry); + return this.deobfuscator.getJarIndex().getClassImplementations(this.deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfClassEntry); } public MethodInheritanceTreeNode getMethodInheritance(MethodEntry deobfMethodEntry) { - MethodEntry obfMethodEntry = m_deobfuscator.obfuscateEntry(deobfMethodEntry); - MethodInheritanceTreeNode rootNode = m_deobfuscator.getJarIndex().getMethodInheritance( - m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating), - obfMethodEntry - ); + MethodEntry obfMethodEntry = this.deobfuscator.obfuscateEntry(deobfMethodEntry); + MethodInheritanceTreeNode rootNode = this.deobfuscator.getJarIndex().getMethodInheritance(this.deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfMethodEntry); return MethodInheritanceTreeNode.findNode(rootNode, obfMethodEntry); } public MethodImplementationsTreeNode getMethodImplementations(MethodEntry deobfMethodEntry) { - MethodEntry obfMethodEntry = m_deobfuscator.obfuscateEntry(deobfMethodEntry); - List rootNodes = m_deobfuscator.getJarIndex().getMethodImplementations( - m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating), - obfMethodEntry - ); + MethodEntry obfMethodEntry = this.deobfuscator.obfuscateEntry(deobfMethodEntry); + List rootNodes = this.deobfuscator.getJarIndex().getMethodImplementations(this.deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfMethodEntry); if (rootNodes.isEmpty()) { return null; } @@ -190,45 +166,39 @@ public class GuiController { } public FieldReferenceTreeNode getFieldReferences(FieldEntry deobfFieldEntry) { - FieldEntry obfFieldEntry = m_deobfuscator.obfuscateEntry(deobfFieldEntry); - FieldReferenceTreeNode rootNode = new FieldReferenceTreeNode( - m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating), - obfFieldEntry - ); - rootNode.load(m_deobfuscator.getJarIndex(), true); + FieldEntry obfFieldEntry = this.deobfuscator.obfuscateEntry(deobfFieldEntry); + FieldReferenceTreeNode rootNode = new FieldReferenceTreeNode(this.deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfFieldEntry); + rootNode.load(this.deobfuscator.getJarIndex(), true); return rootNode; } public BehaviorReferenceTreeNode getMethodReferences(BehaviorEntry deobfBehaviorEntry) { - BehaviorEntry obfBehaviorEntry = m_deobfuscator.obfuscateEntry(deobfBehaviorEntry); - BehaviorReferenceTreeNode rootNode = new BehaviorReferenceTreeNode( - m_deobfuscator.getTranslator(TranslationDirection.Deobfuscating), - obfBehaviorEntry - ); - rootNode.load(m_deobfuscator.getJarIndex(), true); + BehaviorEntry obfBehaviorEntry = this.deobfuscator.obfuscateEntry(deobfBehaviorEntry); + BehaviorReferenceTreeNode rootNode = new BehaviorReferenceTreeNode(this.deobfuscator.getTranslator(TranslationDirection.Deobfuscating), obfBehaviorEntry); + rootNode.load(this.deobfuscator.getJarIndex(), true); return rootNode; } public void rename(EntryReference deobfReference, String newName) { - EntryReference obfReference = m_deobfuscator.obfuscateReference(deobfReference); - m_deobfuscator.rename(obfReference.getNameableEntry(), newName); - m_isDirty = true; + EntryReference obfReference = this.deobfuscator.obfuscateReference(deobfReference); + this.deobfuscator.rename(obfReference.getNameableEntry(), newName); + this.isDirty = true; refreshClasses(); refreshCurrentClass(obfReference); } public void removeMapping(EntryReference deobfReference) { - EntryReference obfReference = m_deobfuscator.obfuscateReference(deobfReference); - m_deobfuscator.removeMapping(obfReference.getNameableEntry()); - m_isDirty = true; + EntryReference obfReference = this.deobfuscator.obfuscateReference(deobfReference); + this.deobfuscator.removeMapping(obfReference.getNameableEntry()); + this.isDirty = true; refreshClasses(); refreshCurrentClass(obfReference); } public void markAsDeobfuscated(EntryReference deobfReference) { - EntryReference obfReference = m_deobfuscator.obfuscateReference(deobfReference); - m_deobfuscator.markAsDeobfuscated(obfReference.getNameableEntry()); - m_isDirty = true; + EntryReference obfReference = this.deobfuscator.obfuscateReference(deobfReference); + this.deobfuscator.markAsDeobfuscated(obfReference.getNameableEntry()); + this.isDirty = true; refreshClasses(); refreshCurrentClass(obfReference); } @@ -237,7 +207,7 @@ public class GuiController { if (deobfEntry == null) { throw new IllegalArgumentException("Entry cannot be null!"); } - openReference(new EntryReference(deobfEntry, deobfEntry.getName())); + openReference(new EntryReference<>(deobfEntry, deobfEntry.getName())); } public void openReference(EntryReference deobfReference) { @@ -246,51 +216,51 @@ public class GuiController { } // get the reference target class - EntryReference obfReference = m_deobfuscator.obfuscateReference(deobfReference); + EntryReference obfReference = this.deobfuscator.obfuscateReference(deobfReference); ClassEntry obfClassEntry = obfReference.getLocationClassEntry().getOutermostClassEntry(); - if (!m_deobfuscator.isObfuscatedIdentifier(obfClassEntry)) { + if (!this.deobfuscator.isObfuscatedIdentifier(obfClassEntry)) { throw new IllegalArgumentException("Obfuscated class " + obfClassEntry + " was not found in the jar!"); } - if (m_currentObfClass == null || !m_currentObfClass.equals(obfClassEntry)) { + if (this.currentObfClass == null || !this.currentObfClass.equals(obfClassEntry)) { // deobfuscate the class, then navigate to the reference - m_currentObfClass = obfClassEntry; - deobfuscate(m_currentObfClass, obfReference); + this.currentObfClass = obfClassEntry; + deobfuscate(this.currentObfClass, obfReference); } else { showReference(obfReference); } } private void showReference(EntryReference obfReference) { - EntryReference deobfReference = m_deobfuscator.deobfuscateReference(obfReference); - Collection tokens = m_index.getReferenceTokens(deobfReference); + EntryReference deobfReference = this.deobfuscator.deobfuscateReference(obfReference); + Collection tokens = this.index.getReferenceTokens(deobfReference); if (tokens.isEmpty()) { // DEBUG - System.err.println(String.format("WARNING: no tokens found for %s in %s", deobfReference, m_currentObfClass)); + System.err.println(String.format("WARNING: no tokens found for %s in %s", deobfReference, this.currentObfClass)); } else { - m_gui.showTokens(tokens); + this.gui.showTokens(tokens); } } public void savePreviousReference(EntryReference deobfReference) { - m_referenceStack.push(m_deobfuscator.obfuscateReference(deobfReference)); + this.referenceStack.push(this.deobfuscator.obfuscateReference(deobfReference)); } public void openPreviousReference() { if (hasPreviousLocation()) { - openReference(m_deobfuscator.deobfuscateReference(m_referenceStack.pop())); + openReference(this.deobfuscator.deobfuscateReference(this.referenceStack.pop())); } } public boolean hasPreviousLocation() { - return !m_referenceStack.isEmpty(); + return !this.referenceStack.isEmpty(); } private void refreshClasses() { List obfClasses = Lists.newArrayList(); List deobfClasses = Lists.newArrayList(); - m_deobfuscator.getSeparatedClasses(obfClasses, deobfClasses); - m_gui.setObfClasses(obfClasses); - m_gui.setDeobfClasses(deobfClasses); + this.deobfuscator.getSeparatedClasses(obfClasses, deobfClasses); + this.gui.setObfClasses(obfClasses); + this.gui.setDeobfClasses(deobfClasses); } private void refreshCurrentClass() { @@ -298,29 +268,29 @@ public class GuiController { } private void refreshCurrentClass(EntryReference obfReference) { - if (m_currentObfClass != null) { - deobfuscate(m_currentObfClass, obfReference); + if (this.currentObfClass != null) { + deobfuscate(this.currentObfClass, obfReference); } } private void deobfuscate(final ClassEntry classEntry, final EntryReference obfReference) { - m_gui.setSource("(deobfuscating...)"); + this.gui.setSource("(deobfuscating...)"); // run the deobfuscator in a separate thread so we don't block the GUI event queue new Thread() { @Override public void run() { // decompile,deobfuscate the bytecode - CompilationUnit sourceTree = m_deobfuscator.getSourceTree(classEntry.getClassName()); + CompilationUnit sourceTree = deobfuscator.getSourceTree(classEntry.getClassName()); if (sourceTree == null) { // decompilation of this class is not supported - m_gui.setSource("Unable to find class: " + classEntry); + gui.setSource("Unable to find class: " + classEntry); return; } - String source = m_deobfuscator.getSource(sourceTree); - m_index = m_deobfuscator.getSourceIndex(sourceTree, source); - m_gui.setSource(m_index.getSource()); + String source = deobfuscator.getSource(sourceTree); + index = deobfuscator.getSourceIndex(sourceTree, source); + gui.setSource(index.getSource()); if (obfReference != null) { showReference(obfReference); } @@ -329,8 +299,8 @@ public class GuiController { List obfuscatedTokens = Lists.newArrayList(); List deobfuscatedTokens = Lists.newArrayList(); List otherTokens = Lists.newArrayList(); - for (Token token : m_index.referenceTokens()) { - EntryReference reference = m_index.getDeobfReference(token); + for (Token token : index.referenceTokens()) { + EntryReference reference = index.getDeobfReference(token); if (referenceIsRenameable(reference)) { if (entryHasDeobfuscatedName(reference.getNameableEntry())) { deobfuscatedTokens.add(token); @@ -341,7 +311,7 @@ public class GuiController { otherTokens.add(token); } } - m_gui.setHighlightedTokens(obfuscatedTokens, deobfuscatedTokens, otherTokens); + gui.setHighlightedTokens(obfuscatedTokens, deobfuscatedTokens, otherTokens); } }.start(); } -- cgit v1.2.3