diff options
Diffstat (limited to 'src/cuchaz/enigma/gui/GuiController.java')
| -rw-r--r-- | src/cuchaz/enigma/gui/GuiController.java | 75 |
1 files changed, 48 insertions, 27 deletions
diff --git a/src/cuchaz/enigma/gui/GuiController.java b/src/cuchaz/enigma/gui/GuiController.java index dfa2557..a35db05 100644 --- a/src/cuchaz/enigma/gui/GuiController.java +++ b/src/cuchaz/enigma/gui/GuiController.java | |||
| @@ -14,6 +14,7 @@ import java.io.File; | |||
| 14 | import java.io.FileReader; | 14 | import java.io.FileReader; |
| 15 | import java.io.FileWriter; | 15 | import java.io.FileWriter; |
| 16 | import java.io.IOException; | 16 | import java.io.IOException; |
| 17 | import java.util.Collection; | ||
| 17 | import java.util.Deque; | 18 | import java.util.Deque; |
| 18 | import java.util.List; | 19 | import java.util.List; |
| 19 | 20 | ||
| @@ -45,7 +46,7 @@ public class GuiController | |||
| 45 | private SourceIndex m_index; | 46 | private SourceIndex m_index; |
| 46 | private ClassEntry m_currentObfClass; | 47 | private ClassEntry m_currentObfClass; |
| 47 | private boolean m_isDirty; | 48 | private boolean m_isDirty; |
| 48 | private Deque<EntryReference<Entry,Entry>> m_referenceStack; // TODO: make a location class, can be either Entry or EntryReference | 49 | private Deque<EntryReference<Entry,Entry>> m_referenceStack; |
| 49 | 50 | ||
| 50 | public GuiController( Gui gui ) | 51 | public GuiController( Gui gui ) |
| 51 | { | 52 | { |
| @@ -111,7 +112,6 @@ public class GuiController | |||
| 111 | { | 112 | { |
| 112 | return null; | 113 | return null; |
| 113 | } | 114 | } |
| 114 | |||
| 115 | return m_index.getReferenceToken( pos ); | 115 | return m_index.getReferenceToken( pos ); |
| 116 | } | 116 | } |
| 117 | 117 | ||
| @@ -124,6 +124,19 @@ public class GuiController | |||
| 124 | return m_index.getDeobfReference( token ); | 124 | return m_index.getDeobfReference( token ); |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | public ReadableToken getReadableToken( Token token ) | ||
| 128 | { | ||
| 129 | if( m_index == null ) | ||
| 130 | { | ||
| 131 | return null; | ||
| 132 | } | ||
| 133 | return new ReadableToken( | ||
| 134 | m_index.getLineNumber( token.start ), | ||
| 135 | m_index.getColumnNumber( token.start ), | ||
| 136 | m_index.getColumnNumber( token.end ) | ||
| 137 | ); | ||
| 138 | } | ||
| 139 | |||
| 127 | public boolean entryHasMapping( Entry deobfEntry ) | 140 | public boolean entryHasMapping( Entry deobfEntry ) |
| 128 | { | 141 | { |
| 129 | return m_deobfuscator.hasMapping( m_deobfuscator.obfuscateEntry( deobfEntry ) ); | 142 | return m_deobfuscator.hasMapping( m_deobfuscator.obfuscateEntry( deobfEntry ) ); |
| @@ -134,8 +147,9 @@ public class GuiController | |||
| 134 | return m_deobfuscator.isObfuscatedIdentifier( m_deobfuscator.obfuscateEntry( deobfEntry ) ); | 147 | return m_deobfuscator.isObfuscatedIdentifier( m_deobfuscator.obfuscateEntry( deobfEntry ) ); |
| 135 | } | 148 | } |
| 136 | 149 | ||
| 137 | public ClassInheritanceTreeNode getClassInheritance( ClassEntry obfClassEntry ) | 150 | public ClassInheritanceTreeNode getClassInheritance( ClassEntry deobfClassEntry ) |
| 138 | { | 151 | { |
| 152 | ClassEntry obfClassEntry = m_deobfuscator.obfuscateEntry( deobfClassEntry ); | ||
| 139 | ClassInheritanceTreeNode rootNode = m_deobfuscator.getJarIndex().getClassInheritance( | 153 | ClassInheritanceTreeNode rootNode = m_deobfuscator.getJarIndex().getClassInheritance( |
| 140 | m_deobfuscator.getTranslator( TranslationDirection.Deobfuscating ), | 154 | m_deobfuscator.getTranslator( TranslationDirection.Deobfuscating ), |
| 141 | obfClassEntry | 155 | obfClassEntry |
| @@ -143,8 +157,9 @@ public class GuiController | |||
| 143 | return ClassInheritanceTreeNode.findNode( rootNode, obfClassEntry ); | 157 | return ClassInheritanceTreeNode.findNode( rootNode, obfClassEntry ); |
| 144 | } | 158 | } |
| 145 | 159 | ||
| 146 | public MethodInheritanceTreeNode getMethodInheritance( MethodEntry obfMethodEntry ) | 160 | public MethodInheritanceTreeNode getMethodInheritance( MethodEntry deobfMethodEntry ) |
| 147 | { | 161 | { |
| 162 | MethodEntry obfMethodEntry = m_deobfuscator.obfuscateEntry( deobfMethodEntry ); | ||
| 148 | MethodInheritanceTreeNode rootNode = m_deobfuscator.getJarIndex().getMethodInheritance( | 163 | MethodInheritanceTreeNode rootNode = m_deobfuscator.getJarIndex().getMethodInheritance( |
| 149 | m_deobfuscator.getTranslator( TranslationDirection.Deobfuscating ), | 164 | m_deobfuscator.getTranslator( TranslationDirection.Deobfuscating ), |
| 150 | obfMethodEntry | 165 | obfMethodEntry |
| @@ -152,8 +167,9 @@ public class GuiController | |||
| 152 | return MethodInheritanceTreeNode.findNode( rootNode, obfMethodEntry ); | 167 | return MethodInheritanceTreeNode.findNode( rootNode, obfMethodEntry ); |
| 153 | } | 168 | } |
| 154 | 169 | ||
| 155 | public FieldReferenceTreeNode getFieldReferences( FieldEntry obfFieldEntry ) | 170 | public FieldReferenceTreeNode getFieldReferences( FieldEntry deobfFieldEntry ) |
| 156 | { | 171 | { |
| 172 | FieldEntry obfFieldEntry = m_deobfuscator.obfuscateEntry( deobfFieldEntry ); | ||
| 157 | FieldReferenceTreeNode rootNode = new FieldReferenceTreeNode( | 173 | FieldReferenceTreeNode rootNode = new FieldReferenceTreeNode( |
| 158 | m_deobfuscator.getTranslator( TranslationDirection.Deobfuscating ), | 174 | m_deobfuscator.getTranslator( TranslationDirection.Deobfuscating ), |
| 159 | obfFieldEntry | 175 | obfFieldEntry |
| @@ -162,11 +178,12 @@ public class GuiController | |||
| 162 | return rootNode; | 178 | return rootNode; |
| 163 | } | 179 | } |
| 164 | 180 | ||
| 165 | public BehaviorReferenceTreeNode getMethodReferences( BehaviorEntry obfEntry ) | 181 | public BehaviorReferenceTreeNode getMethodReferences( BehaviorEntry deobfBehaviorEntry ) |
| 166 | { | 182 | { |
| 183 | BehaviorEntry obfBehaviorEntry = m_deobfuscator.obfuscateEntry( deobfBehaviorEntry ); | ||
| 167 | BehaviorReferenceTreeNode rootNode = new BehaviorReferenceTreeNode( | 184 | BehaviorReferenceTreeNode rootNode = new BehaviorReferenceTreeNode( |
| 168 | m_deobfuscator.getTranslator( TranslationDirection.Deobfuscating ), | 185 | m_deobfuscator.getTranslator( TranslationDirection.Deobfuscating ), |
| 169 | obfEntry | 186 | obfBehaviorEntry |
| 170 | ); | 187 | ); |
| 171 | rootNode.load( m_deobfuscator.getJarIndex(), true ); | 188 | rootNode.load( m_deobfuscator.getJarIndex(), true ); |
| 172 | return rootNode; | 189 | return rootNode; |
| @@ -181,13 +198,13 @@ public class GuiController | |||
| 181 | refreshCurrentClass( obfReference ); | 198 | refreshCurrentClass( obfReference ); |
| 182 | } | 199 | } |
| 183 | 200 | ||
| 184 | public void openDeclaration( Entry entry ) | 201 | public void openDeclaration( Entry deobfEntry ) |
| 185 | { | 202 | { |
| 186 | if( entry == null ) | 203 | if( deobfEntry == null ) |
| 187 | { | 204 | { |
| 188 | throw new IllegalArgumentException( "Entry cannot be null!" ); | 205 | throw new IllegalArgumentException( "Entry cannot be null!" ); |
| 189 | } | 206 | } |
| 190 | openReference( new EntryReference<Entry,Entry>( entry ) ); | 207 | openReference( new EntryReference<Entry,Entry>( deobfEntry ) ); |
| 191 | } | 208 | } |
| 192 | 209 | ||
| 193 | public void openReference( EntryReference<Entry,Entry> deobfReference ) | 210 | public void openReference( EntryReference<Entry,Entry> deobfReference ) |
| @@ -208,8 +225,22 @@ public class GuiController | |||
| 208 | } | 225 | } |
| 209 | else | 226 | else |
| 210 | { | 227 | { |
| 211 | // the class file is already open, just navigate to the reference | 228 | showReference( obfReference ); |
| 212 | m_gui.showToken( m_index.getReferenceToken( deobfReference ) ); | 229 | } |
| 230 | } | ||
| 231 | |||
| 232 | private void showReference( EntryReference<Entry,Entry> obfReference ) | ||
| 233 | { | ||
| 234 | EntryReference<Entry,Entry> deobfReference = m_deobfuscator.deobfuscateReference( obfReference ); | ||
| 235 | Collection<Token> tokens = m_index.getReferenceTokens( deobfReference ); | ||
| 236 | if( tokens.isEmpty() ) | ||
| 237 | { | ||
| 238 | // DEBUG | ||
| 239 | System.err.println( String.format( "WARNING: no tokens found for %s in %s", deobfReference, m_currentObfClass ) ); | ||
| 240 | } | ||
| 241 | else | ||
| 242 | { | ||
| 243 | m_gui.showTokens( tokens ); | ||
| 213 | } | 244 | } |
| 214 | } | 245 | } |
| 215 | 246 | ||
| @@ -245,15 +276,15 @@ public class GuiController | |||
| 245 | refreshCurrentClass( null ); | 276 | refreshCurrentClass( null ); |
| 246 | } | 277 | } |
| 247 | 278 | ||
| 248 | private void refreshCurrentClass( EntryReference<Entry,Entry> obfReferenceToShow ) | 279 | private void refreshCurrentClass( EntryReference<Entry,Entry> obfReference ) |
| 249 | { | 280 | { |
| 250 | if( m_currentObfClass != null ) | 281 | if( m_currentObfClass != null ) |
| 251 | { | 282 | { |
| 252 | deobfuscate( m_currentObfClass, obfReferenceToShow ); | 283 | deobfuscate( m_currentObfClass, obfReference ); |
| 253 | } | 284 | } |
| 254 | } | 285 | } |
| 255 | 286 | ||
| 256 | private void deobfuscate( final ClassEntry classEntry, final EntryReference<Entry,Entry> obfReferenceToShow ) | 287 | private void deobfuscate( final ClassEntry classEntry, final EntryReference<Entry,Entry> obfReference ) |
| 257 | { | 288 | { |
| 258 | m_gui.setSource( "(deobfuscating...)" ); | 289 | m_gui.setSource( "(deobfuscating...)" ); |
| 259 | 290 | ||
| @@ -266,19 +297,9 @@ public class GuiController | |||
| 266 | // decompile,deobfuscate the bytecode | 297 | // decompile,deobfuscate the bytecode |
| 267 | m_index = m_deobfuscator.getSource( classEntry.getClassName() ); | 298 | m_index = m_deobfuscator.getSource( classEntry.getClassName() ); |
| 268 | m_gui.setSource( m_index.getSource() ); | 299 | m_gui.setSource( m_index.getSource() ); |
| 269 | if( obfReferenceToShow != null ) | 300 | if( obfReference != null ) |
| 270 | { | 301 | { |
| 271 | EntryReference<Entry,Entry> deobfReferenceToShow = m_deobfuscator.deobfuscateReference( obfReferenceToShow ); | 302 | showReference( obfReference ); |
| 272 | Token token = m_index.getReferenceToken( deobfReferenceToShow ); | ||
| 273 | if( token == null ) | ||
| 274 | { | ||
| 275 | // DEBUG | ||
| 276 | System.out.println( "WARNING: can't find token for " + obfReferenceToShow + " -> " + deobfReferenceToShow ); | ||
| 277 | } | ||
| 278 | else | ||
| 279 | { | ||
| 280 | m_gui.showToken( token ); | ||
| 281 | } | ||
| 282 | } | 303 | } |
| 283 | 304 | ||
| 284 | // set the highlighted tokens | 305 | // set the highlighted tokens |