From cf3ffcee30083a71e68e3edb9ecbb936cc255992 Mon Sep 17 00:00:00 2001 From: jeff Date: Sun, 28 Sep 2014 15:20:54 -0400 Subject: added proper support for renaming constructors --- src/cuchaz/enigma/Deobfuscator.java | 70 +++++++++++++--------- src/cuchaz/enigma/analysis/EntryReference.java | 43 +++++++++++-- src/cuchaz/enigma/analysis/JarIndex.java | 7 ++- src/cuchaz/enigma/analysis/SourceIndex.java | 29 ++++++--- .../analysis/SourceIndexBehaviorVisitor.java | 27 ++------- .../enigma/analysis/SourceIndexClassVisitor.java | 6 +- src/cuchaz/enigma/analysis/Token.java | 10 ++++ src/cuchaz/enigma/analysis/TreeDumpVisitor.java | 2 +- src/cuchaz/enigma/gui/Gui.java | 15 ++--- src/cuchaz/enigma/gui/GuiController.java | 34 +++++++---- test/cuchaz/enigma/EntryFactory.java | 8 +-- 11 files changed, 159 insertions(+), 92 deletions(-) diff --git a/src/cuchaz/enigma/Deobfuscator.java b/src/cuchaz/enigma/Deobfuscator.java index 44845ba2..ff83d21a 100644 --- a/src/cuchaz/enigma/Deobfuscator.java +++ b/src/cuchaz/enigma/Deobfuscator.java @@ -40,6 +40,7 @@ import cuchaz.enigma.analysis.JarIndex; import cuchaz.enigma.analysis.SourceIndex; import cuchaz.enigma.analysis.SourceIndexVisitor; import cuchaz.enigma.analysis.Token; +import cuchaz.enigma.analysis.TreeDumpVisitor; import cuchaz.enigma.mapping.ArgumentEntry; import cuchaz.enigma.mapping.BehaviorEntry; import cuchaz.enigma.mapping.BehaviorEntryFactory; @@ -337,7 +338,7 @@ public class Deobfuscator // DEBUG //sourceTree.acceptVisitor( new TreeDumpVisitor( new File( "tree.txt" ) ), null ); - + // resolve all the classes in the source references for( Token token : index.referenceTokens() ) { @@ -454,7 +455,8 @@ public class Deobfuscator } return new EntryReference( obfuscateEntry( deobfReference.entry ), - obfuscateEntry( deobfReference.context ) + obfuscateEntry( deobfReference.context ), + deobfReference ); } @@ -466,75 +468,83 @@ public class Deobfuscator } return new EntryReference( deobfuscateEntry( obfReference.entry ), - deobfuscateEntry( obfReference.context ) + deobfuscateEntry( obfReference.context ), + obfReference ); } + public boolean isObfuscatedIdentifier( Entry obfEntry ) + { + return m_jarIndex.containsObfEntry( obfEntry ); + } + + public boolean isRenameable( EntryReference obfReference ) + { + return obfReference.isNamed() && isObfuscatedIdentifier( obfReference.getNameableEntry() ); + } + + // NOTE: these methods are a bit messy... oh well - public void rename( Entry obfEntry, String newName ) + public boolean hasDeobfuscatedName( Entry obfEntry ) { + Translator translator = getTranslator( TranslationDirection.Deobfuscating ); if( obfEntry instanceof ClassEntry ) { - m_renamer.setClassName( (ClassEntry)obfEntry, Descriptor.toJvmName( newName ) ); + return translator.translate( (ClassEntry)obfEntry ) != null; } else if( obfEntry instanceof FieldEntry ) { - m_renamer.setFieldName( (FieldEntry)obfEntry, newName ); + return translator.translate( (FieldEntry)obfEntry ) != null; } else if( obfEntry instanceof MethodEntry ) { - m_renamer.setMethodTreeName( (MethodEntry)obfEntry, newName ); + return translator.translate( (MethodEntry)obfEntry ) != null; } else if( obfEntry instanceof ConstructorEntry ) { - m_renamer.setClassName( obfEntry.getClassEntry(), newName ); + // constructors have no names + return false; } else if( obfEntry instanceof ArgumentEntry ) { - m_renamer.setArgumentName( (ArgumentEntry)obfEntry, newName ); + return translator.translate( (ArgumentEntry)obfEntry ) != null; } else { throw new Error( "Unknown entry type: " + obfEntry.getClass().getName() ); } - - // clear caches - m_translatorCache.clear(); } - - public boolean hasMapping( Entry obfEntry ) + + public void rename( Entry obfEntry, String newName ) { - Translator translator = getTranslator( TranslationDirection.Deobfuscating ); if( obfEntry instanceof ClassEntry ) { - return translator.translate( (ClassEntry)obfEntry ) != null; + m_renamer.setClassName( (ClassEntry)obfEntry, Descriptor.toJvmName( newName ) ); } else if( obfEntry instanceof FieldEntry ) { - return translator.translate( (FieldEntry)obfEntry ) != null; + m_renamer.setFieldName( (FieldEntry)obfEntry, newName ); } else if( obfEntry instanceof MethodEntry ) { - return translator.translate( (MethodEntry)obfEntry ) != null; + m_renamer.setMethodTreeName( (MethodEntry)obfEntry, newName ); } else if( obfEntry instanceof ConstructorEntry ) { - return translator.translate( obfEntry.getClassEntry() ) != null; + throw new IllegalArgumentException( "Cannot rename constructors" ); } else if( obfEntry instanceof ArgumentEntry ) { - return translator.translate( (ArgumentEntry)obfEntry ) != null; + m_renamer.setArgumentName( (ArgumentEntry)obfEntry, newName ); } else { throw new Error( "Unknown entry type: " + obfEntry.getClass().getName() ); } - } - - public boolean isObfuscatedIdentifier( Entry obfEntry ) - { - return m_jarIndex.containsObfEntry( obfEntry ); + + // clear caches + m_translatorCache.clear(); } public void removeMapping( Entry obfEntry ) @@ -553,7 +563,7 @@ public class Deobfuscator } else if( obfEntry instanceof ConstructorEntry ) { - m_renamer.removeClassMapping( obfEntry.getClassEntry() ); + throw new IllegalArgumentException( "Cannot rename constructors" ); } else if( obfEntry instanceof ArgumentEntry ) { @@ -563,6 +573,9 @@ public class Deobfuscator { throw new Error( "Unknown entry type: " + obfEntry ); } + + // clear caches + m_translatorCache.clear(); } public void markAsDeobfuscated( Entry obfEntry ) @@ -581,7 +594,7 @@ public class Deobfuscator } else if( obfEntry instanceof ConstructorEntry ) { - m_renamer.markClassAsDeobfuscated( obfEntry.getClassEntry() ); + throw new IllegalArgumentException( "Cannot rename constructors" ); } else if( obfEntry instanceof ArgumentEntry ) { @@ -591,5 +604,8 @@ public class Deobfuscator { throw new Error( "Unknown entry type: " + obfEntry ); } + + // clear caches + m_translatorCache.clear(); } } diff --git a/src/cuchaz/enigma/analysis/EntryReference.java b/src/cuchaz/enigma/analysis/EntryReference.java index 768c1132..df977fb5 100644 --- a/src/cuchaz/enigma/analysis/EntryReference.java +++ b/src/cuchaz/enigma/analysis/EntryReference.java @@ -10,21 +10,28 @@ ******************************************************************************/ package cuchaz.enigma.analysis; +import java.util.Arrays; +import java.util.List; + import cuchaz.enigma.Util; import cuchaz.enigma.mapping.ClassEntry; +import cuchaz.enigma.mapping.ConstructorEntry; import cuchaz.enigma.mapping.Entry; public class EntryReference { + private static final List ConstructorNonNames = Arrays.asList( "this", "super" ); public E entry; public C context; - public EntryReference( E entry ) + private boolean m_isNamed; + + public EntryReference( E entry, String sourceName ) { - this( entry, null ); + this( entry, sourceName, null ); } - public EntryReference( E entry, C context ) + public EntryReference( E entry, String sourceName, C context ) { if( entry == null ) { @@ -33,9 +40,22 @@ public class EntryReference this.entry = entry; this.context = context; + + m_isNamed = sourceName != null && sourceName.length() > 0; + if( entry instanceof ConstructorEntry && ConstructorNonNames.contains( sourceName ) ) + { + m_isNamed = false; + } + } + + public EntryReference( E entry, C context, EntryReference other ) + { + this.entry = entry; + this.context = context; + m_isNamed = other.m_isNamed; } - public ClassEntry getClassEntry( ) + public ClassEntry getLocationClassEntry( ) { if( context != null ) { @@ -44,6 +64,21 @@ public class EntryReference return entry.getClassEntry(); } + public boolean isNamed( ) + { + return m_isNamed; + } + + public Entry getNameableEntry( ) + { + if( entry instanceof ConstructorEntry ) + { + // renaming a constructor really means renaming the class + return entry.getClassEntry(); + } + return entry; + } + @Override public int hashCode( ) { diff --git a/src/cuchaz/enigma/analysis/JarIndex.java b/src/cuchaz/enigma/analysis/JarIndex.java index a2f6bf34..604e4853 100644 --- a/src/cuchaz/enigma/analysis/JarIndex.java +++ b/src/cuchaz/enigma/analysis/JarIndex.java @@ -277,6 +277,7 @@ public class JarIndex } EntryReference reference = new EntryReference( calledMethodEntry, + call.getMethodName(), behaviorEntry ); m_behaviorReferences.put( calledMethodEntry, reference ); @@ -300,6 +301,7 @@ public class JarIndex } EntryReference reference = new EntryReference( calledFieldEntry, + call.getFieldName(), behaviorEntry ); m_fieldReferences.put( calledFieldEntry, reference ); @@ -308,9 +310,6 @@ public class JarIndex @Override public void edit( ConstructorCall call ) { - // TODO: save isSuper in the reference somehow - boolean isSuper = call.getMethodName().equals( "super" ); - String className = Descriptor.toJvmName( call.getClassName() ); ConstructorEntry calledConstructorEntry = new ConstructorEntry( new ClassEntry( className ), @@ -318,6 +317,7 @@ public class JarIndex ); EntryReference reference = new EntryReference( calledConstructorEntry, + call.getMethodName(), behaviorEntry ); m_behaviorReferences.put( calledConstructorEntry, reference ); @@ -333,6 +333,7 @@ public class JarIndex ); EntryReference reference = new EntryReference( calledConstructorEntry, + call.getClassName(), behaviorEntry ); m_behaviorReferences.put( calledConstructorEntry, reference ); diff --git a/src/cuchaz/enigma/analysis/SourceIndex.java b/src/cuchaz/enigma/analysis/SourceIndex.java index 38d10daa..faae1a14 100644 --- a/src/cuchaz/enigma/analysis/SourceIndex.java +++ b/src/cuchaz/enigma/analysis/SourceIndex.java @@ -21,6 +21,7 @@ import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import com.strobel.decompiler.languages.Region; import com.strobel.decompiler.languages.java.ast.AstNode; +import com.strobel.decompiler.languages.java.ast.Identifier; import cuchaz.enigma.mapping.Entry; @@ -58,40 +59,54 @@ public class SourceIndex public Token getToken( AstNode node ) { + // get the text of the node + String name = ""; + if( node instanceof Identifier ) + { + name = ((Identifier)node).getName(); + } + // get a token for this node's region Region region = node.getRegion(); if( region.getBeginLine() == 0 || region.getEndLine() == 0 ) { // DEBUG - //System.err.println( "WARNING: " + node.getNodeType() + " node has invalid region: " + region ); + System.err.println( String.format( "WARNING: %s \"%s\" has invalid region: %s", node.getNodeType(), name, region ) ); return null; } Token token = new Token( toPos( region.getBeginLine(), region.getBeginColumn() ), - toPos( region.getEndLine(), region.getEndColumn() ) + toPos( region.getEndLine(), region.getEndColumn() ), + m_source ); if( token.start == 0 ) { // DEBUG - //System.err.println( "WARNING: " + node.getNodeType() + " node has invalid start: " + region ); + System.err.println( String.format( "WARNING: %s \"%s\" has invalid start: %s", node.getNodeType(), name, region ) ); return null; } + // DEBUG + //System.out.println( String.format( "%s \"%s\" region: %s", node.getNodeType(), name, region ) ); + + /* TODO: double check that we still need this // for tokens representing inner classes, make sure we only get the simple name - int pos = node.toString().lastIndexOf( '$' ); + int pos = node.getText().lastIndexOf( '$' ); if( pos >= 0 ) { token.end -= pos + 1; } + */ return token; } - public void addReference( AstNode node, EntryReference deobfReference ) + public void addReference( AstNode node, Entry deobfEntry, Entry deobfContext ) { Token token = getToken( node ); if( token != null ) { + EntryReference deobfReference = new EntryReference( deobfEntry, token.text, deobfContext ); m_tokenToReference.put( token, deobfReference ); m_referenceToTokens.put( deobfReference, token ); } @@ -102,7 +117,7 @@ public class SourceIndex Token token = getToken( node ); if( token != null ) { - EntryReference reference = new EntryReference( deobfEntry ); + EntryReference reference = new EntryReference( deobfEntry, token.text ); m_tokenToReference.put( token, reference ); m_referenceToTokens.put( reference, token ); m_declarationToToken.put( deobfEntry, token ); @@ -111,7 +126,7 @@ public class SourceIndex public Token getReferenceToken( int pos ) { - Token token = m_tokenToReference.floorKey( new Token( pos, pos ) ); + Token token = m_tokenToReference.floorKey( new Token( pos, pos, null ) ); if( token != null && token.contains( pos ) ) { return token; diff --git a/src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java b/src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java index f307c11d..b883087c 100644 --- a/src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java +++ b/src/cuchaz/enigma/analysis/SourceIndexBehaviorVisitor.java @@ -33,7 +33,6 @@ import cuchaz.enigma.mapping.ArgumentEntry; import cuchaz.enigma.mapping.BehaviorEntry; import cuchaz.enigma.mapping.ClassEntry; import cuchaz.enigma.mapping.ConstructorEntry; -import cuchaz.enigma.mapping.Entry; import cuchaz.enigma.mapping.FieldEntry; import cuchaz.enigma.mapping.MethodEntry; @@ -100,10 +99,7 @@ public class SourceIndexBehaviorVisitor extends SourceIndexVisitor } if( tokenNode != null ) { - index.addReference( - tokenNode, - new EntryReference( behaviorEntry, m_behaviorEntry ) - ); + index.addReference( tokenNode, behaviorEntry, m_behaviorEntry ); } } @@ -124,10 +120,7 @@ public class SourceIndexBehaviorVisitor extends SourceIndexVisitor ClassEntry classEntry = new ClassEntry( ref.getDeclaringType().getInternalName() ); FieldEntry fieldEntry = new FieldEntry( classEntry, ref.getName() ); - index.addReference( - node.getMemberNameToken(), - new EntryReference( fieldEntry, m_behaviorEntry ) - ); + index.addReference( node.getMemberNameToken(), fieldEntry, m_behaviorEntry ); } return recurse( node, index ); @@ -140,10 +133,7 @@ public class SourceIndexBehaviorVisitor extends SourceIndexVisitor if( node.getIdentifierToken().getStartLocation() != TextLocation.EMPTY ) { ClassEntry classEntry = new ClassEntry( ref.getInternalName() ); - index.addReference( - node.getIdentifierToken(), - new EntryReference( classEntry, m_behaviorEntry ) - ); + index.addReference( node.getIdentifierToken(), classEntry, m_behaviorEntry ); } return recurse( node, index ); @@ -178,10 +168,7 @@ public class SourceIndexBehaviorVisitor extends SourceIndexVisitor { ClassEntry classEntry = new ClassEntry( ref.getDeclaringType().getInternalName() ); FieldEntry fieldEntry = new FieldEntry( classEntry, ref.getName() ); - index.addReference( - node.getIdentifierToken(), - new EntryReference( fieldEntry, m_behaviorEntry ) - ); + index.addReference( node.getIdentifierToken(), fieldEntry, m_behaviorEntry ); } return recurse( node, index ); @@ -197,10 +184,8 @@ public class SourceIndexBehaviorVisitor extends SourceIndexVisitor ConstructorEntry constructorEntry = new ConstructorEntry( classEntry, ref.getSignature() ); if( node.getType() instanceof SimpleType ) { - index.addReference( - ((SimpleType)node.getType()).getIdentifierToken(), - new EntryReference( constructorEntry, m_behaviorEntry ) - ); + SimpleType simpleTypeNode = (SimpleType)node.getType(); + index.addReference( simpleTypeNode.getIdentifierToken(), constructorEntry, m_behaviorEntry ); } } diff --git a/src/cuchaz/enigma/analysis/SourceIndexClassVisitor.java b/src/cuchaz/enigma/analysis/SourceIndexClassVisitor.java index 5d8a3833..fc8cd665 100644 --- a/src/cuchaz/enigma/analysis/SourceIndexClassVisitor.java +++ b/src/cuchaz/enigma/analysis/SourceIndexClassVisitor.java @@ -28,7 +28,6 @@ import cuchaz.enigma.mapping.BehaviorEntry; import cuchaz.enigma.mapping.BehaviorEntryFactory; import cuchaz.enigma.mapping.ClassEntry; import cuchaz.enigma.mapping.ConstructorEntry; -import cuchaz.enigma.mapping.Entry; import cuchaz.enigma.mapping.FieldEntry; public class SourceIndexClassVisitor extends SourceIndexVisitor @@ -63,10 +62,7 @@ public class SourceIndexClassVisitor extends SourceIndexVisitor if( node.getIdentifierToken().getStartLocation() != TextLocation.EMPTY ) { ClassEntry classEntry = new ClassEntry( ref.getInternalName() ); - index.addReference( - node.getIdentifierToken(), - new EntryReference( classEntry, m_classEntry ) - ); + index.addReference( node.getIdentifierToken(), classEntry, m_classEntry ); } return recurse( node, index ); diff --git a/src/cuchaz/enigma/analysis/Token.java b/src/cuchaz/enigma/analysis/Token.java index d0f2b70b..5e70db71 100644 --- a/src/cuchaz/enigma/analysis/Token.java +++ b/src/cuchaz/enigma/analysis/Token.java @@ -14,11 +14,21 @@ public class Token implements Comparable { public int start; public int end; + public String text; public Token( int start, int end ) + { + this( start, end, null ); + } + + public Token( int start, int end, String source ) { this.start = start; this.end = end; + if( source != null ) + { + this.text = source.substring( start, end ); + } } public boolean contains( int pos ) diff --git a/src/cuchaz/enigma/analysis/TreeDumpVisitor.java b/src/cuchaz/enigma/analysis/TreeDumpVisitor.java index 12febefd..e6ecb10e 100644 --- a/src/cuchaz/enigma/analysis/TreeDumpVisitor.java +++ b/src/cuchaz/enigma/analysis/TreeDumpVisitor.java @@ -141,7 +141,7 @@ public class TreeDumpVisitor implements IAstVisitor { if( node instanceof Identifier ) { - return "\"" + node.getText() + "\""; + return "\"" + ((Identifier)node).getName() + "\""; } return ""; } diff --git a/src/cuchaz/enigma/gui/Gui.java b/src/cuchaz/enigma/gui/Gui.java index 8bf6ce95..920bc0b9 100644 --- a/src/cuchaz/enigma/gui/Gui.java +++ b/src/cuchaz/enigma/gui/Gui.java @@ -1038,6 +1038,7 @@ public class Gui boolean isMethodEntry = isToken && m_reference.entry instanceof MethodEntry; boolean isConstructorEntry = isToken && m_reference.entry instanceof ConstructorEntry; boolean isInJar = isToken && m_controller.entryIsInJar( m_reference.entry ); + boolean isRenameable = isToken && m_controller.referenceIsRenameable( m_reference ); if( isToken ) { @@ -1048,15 +1049,15 @@ public class Gui clearReference(); } - m_renameMenu.setEnabled( isInJar && isToken ); + m_renameMenu.setEnabled( isRenameable && isToken ); m_showInheritanceMenu.setEnabled( isClassEntry || isMethodEntry || isConstructorEntry ); m_showImplementationsMenu.setEnabled( isClassEntry || isMethodEntry ); m_showCallsMenu.setEnabled( isClassEntry || isFieldEntry || isMethodEntry || isConstructorEntry ); m_openEntryMenu.setEnabled( isInJar && ( isClassEntry || isFieldEntry || isMethodEntry || isConstructorEntry ) ); m_openPreviousMenu.setEnabled( m_controller.hasPreviousLocation() ); - m_toggleMappingMenu.setEnabled( isInJar && isToken ); + m_toggleMappingMenu.setEnabled( isRenameable && isToken ); - if( isToken && m_controller.entryHasMapping( m_reference.entry ) ) + if( isToken && m_controller.entryHasDeobfuscatedName( m_reference.entry ) ) { m_toggleMappingMenu.setText( "Reset to obfuscated" ); } @@ -1082,7 +1083,7 @@ public class Gui private void navigateTo( EntryReference reference ) { - if( !m_controller.entryIsInJar( reference.getClassEntry() ) ) + if( !m_controller.entryIsInJar( reference.getLocationClassEntry() ) ) { // reference is not in the jar. Ignore it return; @@ -1098,7 +1099,7 @@ public class Gui { // init the text box final JTextField text = new JTextField(); - text.setText( m_reference.entry.getName() ); + text.setText( m_reference.getNameableEntry().getName() ); text.setPreferredSize( new Dimension( 360, text.getPreferredSize().height ) ); text.addKeyListener( new KeyAdapter( ) { @@ -1149,7 +1150,7 @@ public class Gui // abort the rename JPanel panel = (JPanel)m_infoPanel.getComponent( 0 ); panel.remove( panel.getComponentCount() - 1 ); - panel.add( GuiTricks.unboldLabel( new JLabel( m_reference.entry.getName(), JLabel.LEFT ) ) ); + panel.add( GuiTricks.unboldLabel( new JLabel( m_reference.getNameableEntry().getName(), JLabel.LEFT ) ) ); m_editor.grabFocus(); @@ -1268,7 +1269,7 @@ public class Gui private void toggleMapping() { - if( m_controller.entryHasMapping( m_reference.entry ) ) + if( m_controller.entryHasDeobfuscatedName( m_reference.entry ) ) { m_controller.removeMapping( m_reference ); } diff --git a/src/cuchaz/enigma/gui/GuiController.java b/src/cuchaz/enigma/gui/GuiController.java index 3adaf91d..c7efbce6 100644 --- a/src/cuchaz/enigma/gui/GuiController.java +++ b/src/cuchaz/enigma/gui/GuiController.java @@ -165,9 +165,9 @@ public class GuiController ); } - public boolean entryHasMapping( Entry deobfEntry ) + public boolean entryHasDeobfuscatedName( Entry deobfEntry ) { - return m_deobfuscator.hasMapping( m_deobfuscator.obfuscateEntry( deobfEntry ) ); + return m_deobfuscator.hasDeobfuscatedName( m_deobfuscator.obfuscateEntry( deobfEntry ) ); } public boolean entryIsInJar( Entry deobfEntry ) @@ -175,6 +175,11 @@ public class GuiController return m_deobfuscator.isObfuscatedIdentifier( m_deobfuscator.obfuscateEntry( deobfEntry ) ); } + public boolean referenceIsRenameable( EntryReference deobfReference ) + { + return m_deobfuscator.isRenameable( m_deobfuscator.obfuscateReference( deobfReference ) ); + } + public ClassInheritanceTreeNode getClassInheritance( ClassEntry deobfClassEntry ) { ClassEntry obfClassEntry = m_deobfuscator.obfuscateEntry( deobfClassEntry ); @@ -243,7 +248,7 @@ public class GuiController public void rename( EntryReference deobfReference, String newName ) { EntryReference obfReference = m_deobfuscator.obfuscateReference( deobfReference ); - m_deobfuscator.rename( obfReference.entry, newName ); + m_deobfuscator.rename( obfReference.getNameableEntry(), newName ); m_isDirty = true; refreshClasses(); refreshCurrentClass( obfReference ); @@ -252,7 +257,7 @@ public class GuiController public void removeMapping( EntryReference deobfReference ) { EntryReference obfReference = m_deobfuscator.obfuscateReference( deobfReference ); - m_deobfuscator.removeMapping( obfReference.entry ); + m_deobfuscator.removeMapping( obfReference.getNameableEntry() ); m_isDirty = true; refreshClasses(); refreshCurrentClass( obfReference ); @@ -261,7 +266,7 @@ public class GuiController public void markAsDeobfuscated( EntryReference deobfReference ) { EntryReference obfReference = m_deobfuscator.obfuscateReference( deobfReference ); - m_deobfuscator.markAsDeobfuscated( obfReference.entry ); + m_deobfuscator.markAsDeobfuscated( obfReference.getNameableEntry() ); m_isDirty = true; refreshClasses(); refreshCurrentClass( obfReference ); @@ -273,7 +278,7 @@ public class GuiController { throw new IllegalArgumentException( "Entry cannot be null!" ); } - openReference( new EntryReference( deobfEntry ) ); + openReference( new EntryReference( deobfEntry, deobfEntry.getName() ) ); } public void openReference( EntryReference deobfReference ) @@ -285,7 +290,7 @@ public class GuiController // get the reference target class EntryReference obfReference = m_deobfuscator.obfuscateReference( deobfReference ); - ClassEntry obfClassEntry = obfReference.getClassEntry().getOuterClassEntry(); + ClassEntry obfClassEntry = obfReference.getLocationClassEntry().getOuterClassEntry(); if( !m_deobfuscator.isObfuscatedIdentifier( obfClassEntry ) ) { throw new IllegalArgumentException( "Obfuscated class " + obfClassEntry + " was not found in the jar!" ); @@ -390,13 +395,16 @@ public class GuiController for( Token token : m_index.referenceTokens() ) { EntryReference reference = m_index.getDeobfReference( token ); - if( entryHasMapping( reference.entry ) ) - { - deobfuscatedTokens.add( token ); - } - else if( entryIsInJar( reference.entry ) ) + if( referenceIsRenameable( reference ) ) { - obfuscatedTokens.add( token ); + if( entryHasDeobfuscatedName( reference.getNameableEntry() ) ) + { + deobfuscatedTokens.add( token ); + } + else + { + obfuscatedTokens.add( token ); + } } else { diff --git a/test/cuchaz/enigma/EntryFactory.java b/test/cuchaz/enigma/EntryFactory.java index 66f83dfd..5a8a4270 100644 --- a/test/cuchaz/enigma/EntryFactory.java +++ b/test/cuchaz/enigma/EntryFactory.java @@ -42,21 +42,21 @@ public class EntryFactory public static EntryReference newFieldReferenceByMethod( FieldEntry fieldEntry, String callerClassName, String callerName, String callerSignature ) { - return new EntryReference( fieldEntry, newMethod( callerClassName, callerName, callerSignature ) ); + return new EntryReference( fieldEntry, "", newMethod( callerClassName, callerName, callerSignature ) ); } public static EntryReference newFieldReferenceByConstructor( FieldEntry fieldEntry, String callerClassName, String callerSignature ) { - return new EntryReference( fieldEntry, newConstructor( callerClassName, callerSignature ) ); + return new EntryReference( fieldEntry, "", newConstructor( callerClassName, callerSignature ) ); } public static EntryReference newBehaviorReferenceByMethod( BehaviorEntry behaviorEntry, String callerClassName, String callerName, String callerSignature ) { - return new EntryReference( behaviorEntry, newMethod( callerClassName, callerName, callerSignature ) ); + return new EntryReference( behaviorEntry, "", newMethod( callerClassName, callerName, callerSignature ) ); } public static EntryReference newBehaviorReferenceByConstructor( BehaviorEntry behaviorEntry, String callerClassName, String callerSignature ) { - return new EntryReference( behaviorEntry, newConstructor( callerClassName, callerSignature ) ); + return new EntryReference( behaviorEntry, "", newConstructor( callerClassName, callerSignature ) ); } } -- cgit v1.2.3