From dc7c8847ab69e946a20a45c955b4a0273e262d48 Mon Sep 17 00:00:00 2001 From: jeff Date: Sun, 10 Aug 2014 22:39:18 -0400 Subject: added backwards navigation --- src/cuchaz/enigma/analysis/SourceIndex.java | 14 ++++----- src/cuchaz/enigma/gui/Gui.java | 26 ++++++++++++++-- src/cuchaz/enigma/gui/GuiController.java | 46 ++++++++++++++++++++++------- 3 files changed, 65 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/cuchaz/enigma/analysis/SourceIndex.java b/src/cuchaz/enigma/analysis/SourceIndex.java index ad94cf00..531f3e04 100644 --- a/src/cuchaz/enigma/analysis/SourceIndex.java +++ b/src/cuchaz/enigma/analysis/SourceIndex.java @@ -79,16 +79,16 @@ public class SourceIndex return token; } - public void add( AstNode node, Entry entry ) + public void add( AstNode node, Entry deobfEntry ) { - m_tokens.put( getToken( node ), entry ); + m_tokens.put( getToken( node ), deobfEntry ); } - public void addDeclaration( AstNode node, Entry entry ) + public void addDeclaration( AstNode node, Entry deobfEntry ) { Token token = getToken( node ); - m_tokens.put( token, entry ); - m_declarations.put( entry, token ); + m_tokens.put( token, deobfEntry ); + m_declarations.put( deobfEntry, token ); } public Token getToken( int pos ) @@ -120,9 +120,9 @@ public class SourceIndex return m_tokens.keySet(); } - public Token getDeclarationToken( Entry entry ) + public Token getDeclarationToken( Entry deobfEntry ) { - return m_declarations.get( entry ); + return m_declarations.get( deobfEntry ); } private int toPos( int line, int col ) diff --git a/src/cuchaz/enigma/gui/Gui.java b/src/cuchaz/enigma/gui/Gui.java index 6666b4c4..62f23918 100644 --- a/src/cuchaz/enigma/gui/Gui.java +++ b/src/cuchaz/enigma/gui/Gui.java @@ -147,6 +147,7 @@ public class Gui private JMenuItem m_renameMenu; private JMenuItem m_inheritanceMenu; private JMenuItem m_openEntryMenu; + private JMenuItem m_openPreviousMenu; // state private EntryPair m_selectedEntryPair; @@ -282,6 +283,7 @@ public class Gui } } ); menu.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_R, 0 ) ); + menu.setEnabled( false ); popupMenu.add( menu ); m_renameMenu = menu; } @@ -295,8 +297,9 @@ public class Gui showInheritance(); } } ); - popupMenu.add( menu ); menu.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_I, 0 ) ); + menu.setEnabled( false ); + popupMenu.add( menu ); m_inheritanceMenu = menu; } { @@ -309,10 +312,26 @@ public class Gui openEntry(); } } ); - menu.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_O, 0 ) ); + menu.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_N, 0 ) ); + menu.setEnabled( false ); popupMenu.add( menu ); m_openEntryMenu = menu; } + { + JMenuItem menu = new JMenuItem( "Go to previous" ); + menu.addActionListener( new ActionListener( ) + { + @Override + public void actionPerformed( ActionEvent event ) + { + m_controller.openPreviousEntry(); + } + } ); + menu.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_P, 0 ) ); + menu.setEnabled( false ); + popupMenu.add( menu ); + m_openPreviousMenu = menu; + } // init inheritance panel m_inheritanceTree = new JTree(); @@ -327,7 +346,7 @@ public class Gui ClassInheritanceTreeNode node = (ClassInheritanceTreeNode)m_inheritanceTree.getSelectionPath().getLastPathComponent(); if( node != null ) { - m_controller.openEntry( new ClassEntry( node.getDeobfClassName() ) ); + m_controller.openEntry( new ClassEntry( node.getObfClassName() ) ); } } } @@ -747,6 +766,7 @@ public class Gui m_inheritanceMenu.setEnabled( isClassEntry || isMethodEntry ); m_openEntryMenu.setEnabled( isClassEntry || isFieldEntry || isMethodEntry ); + m_openPreviousMenu.setEnabled( m_controller.hasPreviousEntry() ); } private void startRename( ) diff --git a/src/cuchaz/enigma/gui/GuiController.java b/src/cuchaz/enigma/gui/GuiController.java index 6a7a7da6..a4228c72 100644 --- a/src/cuchaz/enigma/gui/GuiController.java +++ b/src/cuchaz/enigma/gui/GuiController.java @@ -15,6 +15,7 @@ import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.List; +import java.util.Stack; import com.google.common.collect.Lists; @@ -36,6 +37,7 @@ public class GuiController private SourceIndex m_index; private ClassEntry m_currentClass; private boolean m_isDirty; + private Stack m_entryStack; public GuiController( Gui gui ) { @@ -44,6 +46,7 @@ public class GuiController m_index = null; m_currentClass = null; m_isDirty = false; + m_entryStack = new Stack(); } public boolean isDirty( ) @@ -153,21 +156,42 @@ public class GuiController m_deobfuscator.rename( obfEntry, newName ); m_isDirty = true; refreshClasses(); - refreshCurrentClass( m_deobfuscator.deobfuscateEntry( obfEntry ) ); + refreshCurrentClass( obfEntry ); } - public void openEntry( Entry obfEntry ) + public void openEntry( Entry entry ) { - Entry deobfEntry = m_deobfuscator.deobfuscateEntry( obfEntry ); - if( m_currentClass == null || !m_currentClass.equals( deobfEntry.getClassEntry() ) ) + // go to the entry + Entry obfEntry = m_deobfuscator.obfuscateEntry( entry ); + if( m_currentClass == null || !m_currentClass.equals( obfEntry.getClassEntry() ) ) { m_currentClass = new ClassEntry( obfEntry.getClassEntry() ); - deobfuscate( m_currentClass, deobfEntry ); + deobfuscate( m_currentClass, obfEntry ); } else { - m_gui.showToken( m_index.getDeclarationToken( deobfEntry ) ); + m_gui.showToken( m_index.getDeclarationToken( m_deobfuscator.deobfuscateEntry( obfEntry ) ) ); } + + if( m_entryStack.isEmpty() || !m_entryStack.peek().equals( obfEntry ) ) + { + // update the stack + m_entryStack.push( obfEntry ); + } + } + + public void openPreviousEntry( ) + { + if( hasPreviousEntry() ) + { + m_entryStack.pop(); + openEntry( m_entryStack.peek() ); + } + } + + public boolean hasPreviousEntry( ) + { + return m_entryStack.size() > 1; } private void refreshClasses( ) @@ -184,15 +208,15 @@ public class GuiController refreshCurrentClass( null ); } - private void refreshCurrentClass( Entry entryToShow ) + private void refreshCurrentClass( Entry obfEntryToShow ) { if( m_currentClass != null ) { - deobfuscate( m_currentClass, entryToShow ); + deobfuscate( m_currentClass, obfEntryToShow ); } } - private void deobfuscate( final ClassEntry classEntry, final Entry entryToShow ) + private void deobfuscate( final ClassEntry classEntry, final Entry obfEntryToShow ) { m_gui.setSource( "(deobfuscating...)" ); @@ -205,9 +229,9 @@ public class GuiController // decompile,deobfuscate the bytecode m_index = m_deobfuscator.getSource( classEntry.getClassName() ); m_gui.setSource( m_index.getSource() ); - if( entryToShow != null ) + if( obfEntryToShow != null ) { - m_gui.showToken( m_index.getDeclarationToken( entryToShow ) ); + m_gui.showToken( m_index.getDeclarationToken( m_deobfuscator.deobfuscateEntry( obfEntryToShow ) ) ); } // set the highlighted tokens -- cgit v1.2.3