summaryrefslogtreecommitdiff
path: root/src/cuchaz
diff options
context:
space:
mode:
authorGravatar jeff2014-08-10 22:39:18 -0400
committerGravatar jeff2014-08-10 22:39:18 -0400
commitdc7c8847ab69e946a20a45c955b4a0273e262d48 (patch)
tree13c20f8b9eef74e0557d8621d099db686eb54764 /src/cuchaz
parentrefactored to remove ClassFile class to prep for upcoming stack navigation. I... (diff)
downloadenigma-dc7c8847ab69e946a20a45c955b4a0273e262d48.tar.gz
enigma-dc7c8847ab69e946a20a45c955b4a0273e262d48.tar.xz
enigma-dc7c8847ab69e946a20a45c955b4a0273e262d48.zip
added backwards navigation
Diffstat (limited to 'src/cuchaz')
-rw-r--r--src/cuchaz/enigma/analysis/SourceIndex.java14
-rw-r--r--src/cuchaz/enigma/gui/Gui.java26
-rw-r--r--src/cuchaz/enigma/gui/GuiController.java46
3 files changed, 65 insertions, 21 deletions
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
79 return token; 79 return token;
80 } 80 }
81 81
82 public void add( AstNode node, Entry entry ) 82 public void add( AstNode node, Entry deobfEntry )
83 { 83 {
84 m_tokens.put( getToken( node ), entry ); 84 m_tokens.put( getToken( node ), deobfEntry );
85 } 85 }
86 86
87 public void addDeclaration( AstNode node, Entry entry ) 87 public void addDeclaration( AstNode node, Entry deobfEntry )
88 { 88 {
89 Token token = getToken( node ); 89 Token token = getToken( node );
90 m_tokens.put( token, entry ); 90 m_tokens.put( token, deobfEntry );
91 m_declarations.put( entry, token ); 91 m_declarations.put( deobfEntry, token );
92 } 92 }
93 93
94 public Token getToken( int pos ) 94 public Token getToken( int pos )
@@ -120,9 +120,9 @@ public class SourceIndex
120 return m_tokens.keySet(); 120 return m_tokens.keySet();
121 } 121 }
122 122
123 public Token getDeclarationToken( Entry entry ) 123 public Token getDeclarationToken( Entry deobfEntry )
124 { 124 {
125 return m_declarations.get( entry ); 125 return m_declarations.get( deobfEntry );
126 } 126 }
127 127
128 private int toPos( int line, int col ) 128 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
147 private JMenuItem m_renameMenu; 147 private JMenuItem m_renameMenu;
148 private JMenuItem m_inheritanceMenu; 148 private JMenuItem m_inheritanceMenu;
149 private JMenuItem m_openEntryMenu; 149 private JMenuItem m_openEntryMenu;
150 private JMenuItem m_openPreviousMenu;
150 151
151 // state 152 // state
152 private EntryPair<Entry> m_selectedEntryPair; 153 private EntryPair<Entry> m_selectedEntryPair;
@@ -282,6 +283,7 @@ public class Gui
282 } 283 }
283 } ); 284 } );
284 menu.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_R, 0 ) ); 285 menu.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_R, 0 ) );
286 menu.setEnabled( false );
285 popupMenu.add( menu ); 287 popupMenu.add( menu );
286 m_renameMenu = menu; 288 m_renameMenu = menu;
287 } 289 }
@@ -295,8 +297,9 @@ public class Gui
295 showInheritance(); 297 showInheritance();
296 } 298 }
297 } ); 299 } );
298 popupMenu.add( menu );
299 menu.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_I, 0 ) ); 300 menu.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_I, 0 ) );
301 menu.setEnabled( false );
302 popupMenu.add( menu );
300 m_inheritanceMenu = menu; 303 m_inheritanceMenu = menu;
301 } 304 }
302 { 305 {
@@ -309,10 +312,26 @@ public class Gui
309 openEntry(); 312 openEntry();
310 } 313 }
311 } ); 314 } );
312 menu.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_O, 0 ) ); 315 menu.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_N, 0 ) );
316 menu.setEnabled( false );
313 popupMenu.add( menu ); 317 popupMenu.add( menu );
314 m_openEntryMenu = menu; 318 m_openEntryMenu = menu;
315 } 319 }
320 {
321 JMenuItem menu = new JMenuItem( "Go to previous" );
322 menu.addActionListener( new ActionListener( )
323 {
324 @Override
325 public void actionPerformed( ActionEvent event )
326 {
327 m_controller.openPreviousEntry();
328 }
329 } );
330 menu.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_P, 0 ) );
331 menu.setEnabled( false );
332 popupMenu.add( menu );
333 m_openPreviousMenu = menu;
334 }
316 335
317 // init inheritance panel 336 // init inheritance panel
318 m_inheritanceTree = new JTree(); 337 m_inheritanceTree = new JTree();
@@ -327,7 +346,7 @@ public class Gui
327 ClassInheritanceTreeNode node = (ClassInheritanceTreeNode)m_inheritanceTree.getSelectionPath().getLastPathComponent(); 346 ClassInheritanceTreeNode node = (ClassInheritanceTreeNode)m_inheritanceTree.getSelectionPath().getLastPathComponent();
328 if( node != null ) 347 if( node != null )
329 { 348 {
330 m_controller.openEntry( new ClassEntry( node.getDeobfClassName() ) ); 349 m_controller.openEntry( new ClassEntry( node.getObfClassName() ) );
331 } 350 }
332 } 351 }
333 } 352 }
@@ -747,6 +766,7 @@ public class Gui
747 766
748 m_inheritanceMenu.setEnabled( isClassEntry || isMethodEntry ); 767 m_inheritanceMenu.setEnabled( isClassEntry || isMethodEntry );
749 m_openEntryMenu.setEnabled( isClassEntry || isFieldEntry || isMethodEntry ); 768 m_openEntryMenu.setEnabled( isClassEntry || isFieldEntry || isMethodEntry );
769 m_openPreviousMenu.setEnabled( m_controller.hasPreviousEntry() );
750 } 770 }
751 771
752 private void startRename( ) 772 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;
15import java.io.FileWriter; 15import java.io.FileWriter;
16import java.io.IOException; 16import java.io.IOException;
17import java.util.List; 17import java.util.List;
18import java.util.Stack;
18 19
19import com.google.common.collect.Lists; 20import com.google.common.collect.Lists;
20 21
@@ -36,6 +37,7 @@ public class GuiController
36 private SourceIndex m_index; 37 private SourceIndex m_index;
37 private ClassEntry m_currentClass; 38 private ClassEntry m_currentClass;
38 private boolean m_isDirty; 39 private boolean m_isDirty;
40 private Stack<Entry> m_entryStack;
39 41
40 public GuiController( Gui gui ) 42 public GuiController( Gui gui )
41 { 43 {
@@ -44,6 +46,7 @@ public class GuiController
44 m_index = null; 46 m_index = null;
45 m_currentClass = null; 47 m_currentClass = null;
46 m_isDirty = false; 48 m_isDirty = false;
49 m_entryStack = new Stack<Entry>();
47 } 50 }
48 51
49 public boolean isDirty( ) 52 public boolean isDirty( )
@@ -153,21 +156,42 @@ public class GuiController
153 m_deobfuscator.rename( obfEntry, newName ); 156 m_deobfuscator.rename( obfEntry, newName );
154 m_isDirty = true; 157 m_isDirty = true;
155 refreshClasses(); 158 refreshClasses();
156 refreshCurrentClass( m_deobfuscator.deobfuscateEntry( obfEntry ) ); 159 refreshCurrentClass( obfEntry );
157 } 160 }
158 161
159 public void openEntry( Entry obfEntry ) 162 public void openEntry( Entry entry )
160 { 163 {
161 Entry deobfEntry = m_deobfuscator.deobfuscateEntry( obfEntry ); 164 // go to the entry
162 if( m_currentClass == null || !m_currentClass.equals( deobfEntry.getClassEntry() ) ) 165 Entry obfEntry = m_deobfuscator.obfuscateEntry( entry );
166 if( m_currentClass == null || !m_currentClass.equals( obfEntry.getClassEntry() ) )
163 { 167 {
164 m_currentClass = new ClassEntry( obfEntry.getClassEntry() ); 168 m_currentClass = new ClassEntry( obfEntry.getClassEntry() );
165 deobfuscate( m_currentClass, deobfEntry ); 169 deobfuscate( m_currentClass, obfEntry );
166 } 170 }
167 else 171 else
168 { 172 {
169 m_gui.showToken( m_index.getDeclarationToken( deobfEntry ) ); 173 m_gui.showToken( m_index.getDeclarationToken( m_deobfuscator.deobfuscateEntry( obfEntry ) ) );
170 } 174 }
175
176 if( m_entryStack.isEmpty() || !m_entryStack.peek().equals( obfEntry ) )
177 {
178 // update the stack
179 m_entryStack.push( obfEntry );
180 }
181 }
182
183 public void openPreviousEntry( )
184 {
185 if( hasPreviousEntry() )
186 {
187 m_entryStack.pop();
188 openEntry( m_entryStack.peek() );
189 }
190 }
191
192 public boolean hasPreviousEntry( )
193 {
194 return m_entryStack.size() > 1;
171 } 195 }
172 196
173 private void refreshClasses( ) 197 private void refreshClasses( )
@@ -184,15 +208,15 @@ public class GuiController
184 refreshCurrentClass( null ); 208 refreshCurrentClass( null );
185 } 209 }
186 210
187 private void refreshCurrentClass( Entry entryToShow ) 211 private void refreshCurrentClass( Entry obfEntryToShow )
188 { 212 {
189 if( m_currentClass != null ) 213 if( m_currentClass != null )
190 { 214 {
191 deobfuscate( m_currentClass, entryToShow ); 215 deobfuscate( m_currentClass, obfEntryToShow );
192 } 216 }
193 } 217 }
194 218
195 private void deobfuscate( final ClassEntry classEntry, final Entry entryToShow ) 219 private void deobfuscate( final ClassEntry classEntry, final Entry obfEntryToShow )
196 { 220 {
197 m_gui.setSource( "(deobfuscating...)" ); 221 m_gui.setSource( "(deobfuscating...)" );
198 222
@@ -205,9 +229,9 @@ public class GuiController
205 // decompile,deobfuscate the bytecode 229 // decompile,deobfuscate the bytecode
206 m_index = m_deobfuscator.getSource( classEntry.getClassName() ); 230 m_index = m_deobfuscator.getSource( classEntry.getClassName() );
207 m_gui.setSource( m_index.getSource() ); 231 m_gui.setSource( m_index.getSource() );
208 if( entryToShow != null ) 232 if( obfEntryToShow != null )
209 { 233 {
210 m_gui.showToken( m_index.getDeclarationToken( entryToShow ) ); 234 m_gui.showToken( m_index.getDeclarationToken( m_deobfuscator.deobfuscateEntry( obfEntryToShow ) ) );
211 } 235 }
212 236
213 // set the highlighted tokens 237 // set the highlighted tokens