From c4e35f2d516ade27e8e1a863b4bc356f182f43c2 Mon Sep 17 00:00:00 2001 From: jeff Date: Tue, 19 Aug 2014 00:25:32 -0400 Subject: started new reference navigation system --- src/cuchaz/enigma/gui/Gui.java | 46 +++++++++++++--------- src/cuchaz/enigma/gui/GuiController.java | 65 ++++++++++++++------------------ 2 files changed, 57 insertions(+), 54 deletions(-) (limited to 'src/cuchaz/enigma/gui') diff --git a/src/cuchaz/enigma/gui/Gui.java b/src/cuchaz/enigma/gui/Gui.java index 9ed6dd8..43a0cda 100644 --- a/src/cuchaz/enigma/gui/Gui.java +++ b/src/cuchaz/enigma/gui/Gui.java @@ -66,10 +66,11 @@ import jsyntaxpane.DefaultSyntaxKit; import com.google.common.collect.Lists; import cuchaz.enigma.Constants; +import cuchaz.enigma.analysis.BehaviorReferenceTreeNode; import cuchaz.enigma.analysis.ClassInheritanceTreeNode; -import cuchaz.enigma.analysis.FieldCallsTreeNode; -import cuchaz.enigma.analysis.MethodCallsTreeNode; +import cuchaz.enigma.analysis.FieldReferenceTreeNode; import cuchaz.enigma.analysis.MethodInheritanceTreeNode; +import cuchaz.enigma.analysis.ReferenceTreeNode; import cuchaz.enigma.analysis.Token; import cuchaz.enigma.mapping.ArgumentEntry; import cuchaz.enigma.mapping.ClassEntry; @@ -191,7 +192,7 @@ public class Gui String selected = m_obfClasses.getSelectedValue(); if( selected != null ) { - m_controller.openEntry( new ClassEntry( selected ) ); + m_controller.openDeclaration( new ClassEntry( selected ) ); } } } @@ -217,7 +218,7 @@ public class Gui String selected = m_deobfClasses.getSelectedValue(); if( selected != null ) { - m_controller.openEntry( new ClassEntry( selected ) ); + m_controller.openDeclaration( new ClassEntry( selected ) ); } } } @@ -268,11 +269,11 @@ public class Gui break; case KeyEvent.VK_N: - openEntry(); + openDeclaration(); break; case KeyEvent.VK_P: - m_controller.openPreviousEntry(); + m_controller.openPreviousLocation(); break; case KeyEvent.VK_C: @@ -341,7 +342,7 @@ public class Gui @Override public void actionPerformed( ActionEvent event ) { - openEntry(); + openDeclaration(); } } ); menu.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_N, 0 ) ); @@ -356,7 +357,7 @@ public class Gui @Override public void actionPerformed( ActionEvent event ) { - m_controller.openPreviousEntry(); + m_controller.openPreviousLocation(); } } ); menu.setAccelerator( KeyStroke.getKeyStroke( KeyEvent.VK_P, 0 ) ); @@ -385,14 +386,14 @@ public class Gui Object node = path.getLastPathComponent(); if( node instanceof ClassInheritanceTreeNode ) { - m_controller.openEntry( new ClassEntry( ((ClassInheritanceTreeNode)node).getObfClassName() ) ); + m_controller.openDeclaration( new ClassEntry( ((ClassInheritanceTreeNode)node).getObfClassName() ) ); } else if( node instanceof MethodInheritanceTreeNode ) { MethodInheritanceTreeNode methodNode = (MethodInheritanceTreeNode)node; if( methodNode.isImplemented() ) { - m_controller.openEntry( methodNode.getMethodEntry() ); + m_controller.openDeclaration( methodNode.getMethodEntry() ); } } } @@ -407,6 +408,7 @@ public class Gui m_callsTree.setModel( null ); m_callsTree.addMouseListener( new MouseAdapter( ) { + @SuppressWarnings( "unchecked" ) @Override public void mouseClicked( MouseEvent event ) { @@ -420,9 +422,17 @@ public class Gui } Object node = path.getLastPathComponent(); - if( node instanceof MethodCallsTreeNode ) + if( node instanceof ReferenceTreeNode ) { - m_controller.openEntry( ((MethodCallsTreeNode)node).getEntry() ); + ReferenceTreeNode referenceNode = ((ReferenceTreeNode)node); + if( referenceNode.getReference() != null ) + { + m_controller.openReference( referenceNode.getReference() ); + } + else + { + m_controller.openDeclaration( referenceNode.getEntry() ); + } } } } @@ -862,7 +872,7 @@ public class Gui m_showInheritanceMenu.setEnabled( isClassEntry || isMethodEntry || isConstructorEntry ); m_showCallsMenu.setEnabled( isFieldEntry || isMethodEntry || isConstructorEntry ); m_openEntryMenu.setEnabled( isClassEntry || isFieldEntry || isMethodEntry || isConstructorEntry ); - m_openPreviousMenu.setEnabled( m_controller.hasPreviousEntry() ); + m_openPreviousMenu.setEnabled( m_controller.hasPreviousLocation() ); } private void startRename( ) @@ -977,17 +987,17 @@ public class Gui if( m_selectedEntryPair.obf instanceof FieldEntry ) { - FieldCallsTreeNode node = m_controller.getFieldCalls( (FieldEntry)m_selectedEntryPair.obf ); + FieldReferenceTreeNode node = m_controller.getFieldReferences( (FieldEntry)m_selectedEntryPair.obf ); m_callsTree.setModel( new DefaultTreeModel( node ) ); } else if( m_selectedEntryPair.obf instanceof MethodEntry ) { - MethodCallsTreeNode node = m_controller.getMethodCalls( (MethodEntry)m_selectedEntryPair.obf ); + BehaviorReferenceTreeNode node = m_controller.getMethodReferences( (MethodEntry)m_selectedEntryPair.obf ); m_callsTree.setModel( new DefaultTreeModel( node ) ); } else if( m_selectedEntryPair.obf instanceof ConstructorEntry ) { - MethodCallsTreeNode node = m_controller.getMethodCalls( (ConstructorEntry)m_selectedEntryPair.obf ); + BehaviorReferenceTreeNode node = m_controller.getMethodReferences( (ConstructorEntry)m_selectedEntryPair.obf ); m_callsTree.setModel( new DefaultTreeModel( node ) ); } @@ -1009,13 +1019,13 @@ public class Gui return new TreePath( nodes.toArray() ); } - private void openEntry( ) + private void openDeclaration( ) { if( m_selectedEntryPair == null ) { return; } - m_controller.openEntry( m_selectedEntryPair.obf ); + m_controller.openDeclaration( m_selectedEntryPair.obf ); } private void close( ) diff --git a/src/cuchaz/enigma/gui/GuiController.java b/src/cuchaz/enigma/gui/GuiController.java index f305e34..f80bec7 100644 --- a/src/cuchaz/enigma/gui/GuiController.java +++ b/src/cuchaz/enigma/gui/GuiController.java @@ -20,14 +20,15 @@ import java.util.Stack; import com.google.common.collect.Lists; import cuchaz.enigma.Deobfuscator; +import cuchaz.enigma.analysis.BehaviorReferenceTreeNode; import cuchaz.enigma.analysis.ClassInheritanceTreeNode; -import cuchaz.enigma.analysis.FieldCallsTreeNode; -import cuchaz.enigma.analysis.MethodCallsTreeNode; +import cuchaz.enigma.analysis.EntryReference; +import cuchaz.enigma.analysis.FieldReferenceTreeNode; import cuchaz.enigma.analysis.MethodInheritanceTreeNode; import cuchaz.enigma.analysis.SourceIndex; import cuchaz.enigma.analysis.Token; +import cuchaz.enigma.mapping.BehaviorEntry; import cuchaz.enigma.mapping.ClassEntry; -import cuchaz.enigma.mapping.ConstructorEntry; import cuchaz.enigma.mapping.Entry; import cuchaz.enigma.mapping.EntryPair; import cuchaz.enigma.mapping.FieldEntry; @@ -44,7 +45,7 @@ public class GuiController private SourceIndex m_index; private ClassEntry m_currentClass; private boolean m_isDirty; - private Stack m_entryStack; + private Stack m_locationStack; // TODO: make a location class, can be either Entry or EntryReference public GuiController( Gui gui ) { @@ -53,7 +54,7 @@ public class GuiController m_index = null; m_currentClass = null; m_isDirty = false; - m_entryStack = new Stack(); + m_locationStack = new Stack(); } public boolean isDirty( ) @@ -157,9 +158,9 @@ public class GuiController return MethodInheritanceTreeNode.findNode( rootNode, obfMethodEntry ); } - public FieldCallsTreeNode getFieldCalls( FieldEntry obfFieldEntry ) + public FieldReferenceTreeNode getFieldReferences( FieldEntry obfFieldEntry ) { - FieldCallsTreeNode rootNode = new FieldCallsTreeNode( + FieldReferenceTreeNode rootNode = new FieldReferenceTreeNode( m_deobfuscator.getTranslator( TranslationDirection.Deobfuscating ), obfFieldEntry ); @@ -167,27 +168,12 @@ public class GuiController return rootNode; } - public MethodCallsTreeNode getMethodCalls( Entry obfEntry ) + public BehaviorReferenceTreeNode getMethodReferences( BehaviorEntry obfEntry ) { - MethodCallsTreeNode rootNode; - if( obfEntry instanceof MethodEntry ) - { - rootNode = new MethodCallsTreeNode( - m_deobfuscator.getTranslator( TranslationDirection.Deobfuscating ), - (MethodEntry)obfEntry - ); - } - else if( obfEntry instanceof ConstructorEntry ) - { - rootNode = new MethodCallsTreeNode( - m_deobfuscator.getTranslator( TranslationDirection.Deobfuscating ), - (ConstructorEntry)obfEntry - ); - } - else - { - throw new IllegalArgumentException( "entry must be a MethodEntry or a ConstructorEntry!" ); - } + BehaviorReferenceTreeNode rootNode = new BehaviorReferenceTreeNode( + m_deobfuscator.getTranslator( TranslationDirection.Deobfuscating ), + obfEntry + ); rootNode.load( m_deobfuscator.getJarIndex(), true ); return rootNode; } @@ -200,7 +186,7 @@ public class GuiController refreshCurrentClass( obfEntry ); } - public void openEntry( Entry entry ) + public void openDeclaration( Entry entry ) { // go to the entry Entry obfEntry = m_deobfuscator.obfuscateEntry( entry ); @@ -214,25 +200,32 @@ public class GuiController m_gui.showToken( m_index.getDeclarationToken( m_deobfuscator.deobfuscateEntry( obfEntry ) ) ); } - if( m_entryStack.isEmpty() || !m_entryStack.peek().equals( obfEntry ) ) + if( m_locationStack.isEmpty() || !m_locationStack.peek().equals( obfEntry ) ) { // update the stack - m_entryStack.push( obfEntry ); + m_locationStack.push( obfEntry ); } } - public void openPreviousEntry( ) + public void openReference( EntryReference reference ) + { + // TODO: find out how to load the n-th reference in a caller + // TEMP: just go to the caller for now + openDeclaration( reference.caller ); + } + + public void openPreviousLocation( ) { - if( hasPreviousEntry() ) + if( hasPreviousLocation() ) { - m_entryStack.pop(); - openEntry( m_entryStack.peek() ); + m_locationStack.pop(); + openDeclaration( m_locationStack.peek() ); } } - public boolean hasPreviousEntry( ) + public boolean hasPreviousLocation( ) { - return m_entryStack.size() > 1; + return m_locationStack.size() > 1; } private void refreshClasses( ) -- cgit v1.2.3