From 5eeee98418bb39367258442a82b75a081a6f91e0 Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 1 Oct 2014 00:04:18 -0400 Subject: fixed inner class renaming bug also added smarter sorting to class mappings --- src/cuchaz/enigma/mapping/Translator.java | 104 +++++++++++------------------- 1 file changed, 36 insertions(+), 68 deletions(-) (limited to 'src/cuchaz/enigma/mapping/Translator.java') diff --git a/src/cuchaz/enigma/mapping/Translator.java b/src/cuchaz/enigma/mapping/Translator.java index 1c69b2f..6cb5240 100644 --- a/src/cuchaz/enigma/mapping/Translator.java +++ b/src/cuchaz/enigma/mapping/Translator.java @@ -10,33 +10,27 @@ ******************************************************************************/ package cuchaz.enigma.mapping; -import java.util.ArrayList; -import java.util.List; import java.util.Map; import com.google.common.collect.Maps; -import cuchaz.enigma.analysis.TranslationIndex; import cuchaz.enigma.mapping.SignatureUpdater.ClassNameUpdater; public class Translator { private TranslationDirection m_direction; private Map m_classes; - private TranslationIndex m_index; public Translator( ) { m_direction = null; m_classes = Maps.newHashMap(); - m_index = new TranslationIndex(); } - public Translator( TranslationDirection direction, Map classes, TranslationIndex index ) + public Translator( TranslationDirection direction, Map classes ) { m_direction = direction; m_classes = classes; - m_index = index; } @SuppressWarnings( "unchecked" ) @@ -138,28 +132,18 @@ public class Translator public String translate( FieldEntry in ) { - for( String className : getSelfAndAncestors( in.getClassName() ) ) + // look for the class + ClassMapping classMapping = findClassMapping( in.getClassEntry() ); + if( classMapping != null ) { - // look for the class - ClassMapping classMapping = findClassMapping( new ClassEntry( className ) ); - if( classMapping != null ) - { - // look for the field - String translatedName = m_direction.choose( - classMapping.getDeobfFieldName( in.getName() ), - classMapping.getObfFieldName( in.getName() ) - ); - if( translatedName != null ) - { - return translatedName; - } - } - - // is the field implemented in this class? - if( m_index.containsField( className, in.getName() ) ) + // look for the field + String translatedName = m_direction.choose( + classMapping.getDeobfFieldName( in.getName() ), + classMapping.getObfFieldName( in.getName() ) + ); + if( translatedName != null ) { - // stop traversing the superclass chain - break; + return translatedName; } } return null; @@ -180,27 +164,23 @@ public class Translator public String translate( MethodEntry in ) { - for( String className : getSelfAndAncestors( in.getClassName() ) ) + // look for class + ClassMapping classMapping = findClassMapping( in.getClassEntry() ); + if( classMapping != null ) { - // look for class - ClassMapping classMapping = findClassMapping( new ClassEntry( className ) ); - if( classMapping != null ) + // look for the method + MethodMapping methodMapping = m_direction.choose( + classMapping.getMethodByObf( in.getName(), in.getSignature() ), + classMapping.getMethodByDeobf( in.getName(), translateSignature( in.getSignature() ) ) + ); + if( methodMapping != null ) { - // look for the method - MethodMapping methodMapping = m_direction.choose( - classMapping.getMethodByObf( in.getName(), in.getSignature() ), - classMapping.getMethodByDeobf( in.getName(), translateSignature( in.getSignature() ) ) + return m_direction.choose( + methodMapping.getDeobfName(), + methodMapping.getObfName() ); - if( methodMapping != null ) - { - return m_direction.choose( - methodMapping.getDeobfName(), - methodMapping.getObfName() - ); - } } } - return null; } @@ -248,27 +228,23 @@ public class Translator public String translate( ArgumentEntry in ) { - for( String className : getSelfAndAncestors( in.getClassName() ) ) + // look for the class + ClassMapping classMapping = findClassMapping( in.getClassEntry() ); + if( classMapping != null ) { - // look for the class - ClassMapping classMapping = findClassMapping( new ClassEntry( className ) ); - if( classMapping != null ) + // look for the method + MethodMapping methodMapping = m_direction.choose( + classMapping.getMethodByObf( in.getMethodName(), in.getMethodSignature() ), + classMapping.getMethodByDeobf( in.getMethodName(), translateSignature( in.getMethodSignature() ) ) + ); + if( methodMapping != null ) { - // look for the method - MethodMapping methodMapping = m_direction.choose( - classMapping.getMethodByObf( in.getMethodName(), in.getMethodSignature() ), - classMapping.getMethodByDeobf( in.getMethodName(), translateSignature( in.getMethodSignature() ) ) + return m_direction.choose( + methodMapping.getDeobfArgumentName( in.getIndex() ), + methodMapping.getObfArgumentName( in.getIndex() ) ); - if( methodMapping != null ) - { - return m_direction.choose( - methodMapping.getDeobfArgumentName( in.getIndex() ), - methodMapping.getObfArgumentName( in.getIndex() ) - ); - } } } - return null; } @@ -303,14 +279,6 @@ public class Translator } ); } - private List getSelfAndAncestors( String className ) - { - List ancestry = new ArrayList(); - ancestry.add( className ); - ancestry.addAll( m_index.getAncestry( className ) ); - return ancestry; - } - private ClassMapping findClassMapping( ClassEntry classEntry ) { ClassMapping classMapping = m_classes.get( classEntry.getOuterClassName() ); @@ -318,7 +286,7 @@ public class Translator { classMapping = m_direction.choose( classMapping.getInnerClassByObf( classEntry.getInnerClassName() ), - classMapping.getInnerClassByDeobf( classEntry.getInnerClassName() ) + classMapping.getInnerClassByDeobfThenObf( classEntry.getInnerClassName() ) ); } return classMapping; -- cgit v1.2.3