diff options
Diffstat (limited to 'src/cuchaz/enigma/mapping/Translator.java')
| -rw-r--r-- | src/cuchaz/enigma/mapping/Translator.java | 104 |
1 files changed, 36 insertions, 68 deletions
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 @@ | |||
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | package cuchaz.enigma.mapping; | 11 | package cuchaz.enigma.mapping; |
| 12 | 12 | ||
| 13 | import java.util.ArrayList; | ||
| 14 | import java.util.List; | ||
| 15 | import java.util.Map; | 13 | import java.util.Map; |
| 16 | 14 | ||
| 17 | import com.google.common.collect.Maps; | 15 | import com.google.common.collect.Maps; |
| 18 | 16 | ||
| 19 | import cuchaz.enigma.analysis.TranslationIndex; | ||
| 20 | import cuchaz.enigma.mapping.SignatureUpdater.ClassNameUpdater; | 17 | import cuchaz.enigma.mapping.SignatureUpdater.ClassNameUpdater; |
| 21 | 18 | ||
| 22 | public class Translator | 19 | public class Translator |
| 23 | { | 20 | { |
| 24 | private TranslationDirection m_direction; | 21 | private TranslationDirection m_direction; |
| 25 | private Map<String,ClassMapping> m_classes; | 22 | private Map<String,ClassMapping> m_classes; |
| 26 | private TranslationIndex m_index; | ||
| 27 | 23 | ||
| 28 | public Translator( ) | 24 | public Translator( ) |
| 29 | { | 25 | { |
| 30 | m_direction = null; | 26 | m_direction = null; |
| 31 | m_classes = Maps.newHashMap(); | 27 | m_classes = Maps.newHashMap(); |
| 32 | m_index = new TranslationIndex(); | ||
| 33 | } | 28 | } |
| 34 | 29 | ||
| 35 | public Translator( TranslationDirection direction, Map<String,ClassMapping> classes, TranslationIndex index ) | 30 | public Translator( TranslationDirection direction, Map<String,ClassMapping> classes ) |
| 36 | { | 31 | { |
| 37 | m_direction = direction; | 32 | m_direction = direction; |
| 38 | m_classes = classes; | 33 | m_classes = classes; |
| 39 | m_index = index; | ||
| 40 | } | 34 | } |
| 41 | 35 | ||
| 42 | @SuppressWarnings( "unchecked" ) | 36 | @SuppressWarnings( "unchecked" ) |
| @@ -138,28 +132,18 @@ public class Translator | |||
| 138 | 132 | ||
| 139 | public String translate( FieldEntry in ) | 133 | public String translate( FieldEntry in ) |
| 140 | { | 134 | { |
| 141 | for( String className : getSelfAndAncestors( in.getClassName() ) ) | 135 | // look for the class |
| 136 | ClassMapping classMapping = findClassMapping( in.getClassEntry() ); | ||
| 137 | if( classMapping != null ) | ||
| 142 | { | 138 | { |
| 143 | // look for the class | 139 | // look for the field |
| 144 | ClassMapping classMapping = findClassMapping( new ClassEntry( className ) ); | 140 | String translatedName = m_direction.choose( |
| 145 | if( classMapping != null ) | 141 | classMapping.getDeobfFieldName( in.getName() ), |
| 146 | { | 142 | classMapping.getObfFieldName( in.getName() ) |
| 147 | // look for the field | 143 | ); |
| 148 | String translatedName = m_direction.choose( | 144 | if( translatedName != null ) |
| 149 | classMapping.getDeobfFieldName( in.getName() ), | ||
| 150 | classMapping.getObfFieldName( in.getName() ) | ||
| 151 | ); | ||
| 152 | if( translatedName != null ) | ||
| 153 | { | ||
| 154 | return translatedName; | ||
| 155 | } | ||
| 156 | } | ||
| 157 | |||
| 158 | // is the field implemented in this class? | ||
| 159 | if( m_index.containsField( className, in.getName() ) ) | ||
| 160 | { | 145 | { |
| 161 | // stop traversing the superclass chain | 146 | return translatedName; |
| 162 | break; | ||
| 163 | } | 147 | } |
| 164 | } | 148 | } |
| 165 | return null; | 149 | return null; |
| @@ -180,27 +164,23 @@ public class Translator | |||
| 180 | 164 | ||
| 181 | public String translate( MethodEntry in ) | 165 | public String translate( MethodEntry in ) |
| 182 | { | 166 | { |
| 183 | for( String className : getSelfAndAncestors( in.getClassName() ) ) | 167 | // look for class |
| 168 | ClassMapping classMapping = findClassMapping( in.getClassEntry() ); | ||
| 169 | if( classMapping != null ) | ||
| 184 | { | 170 | { |
| 185 | // look for class | 171 | // look for the method |
| 186 | ClassMapping classMapping = findClassMapping( new ClassEntry( className ) ); | 172 | MethodMapping methodMapping = m_direction.choose( |
| 187 | if( classMapping != null ) | 173 | classMapping.getMethodByObf( in.getName(), in.getSignature() ), |
| 174 | classMapping.getMethodByDeobf( in.getName(), translateSignature( in.getSignature() ) ) | ||
| 175 | ); | ||
| 176 | if( methodMapping != null ) | ||
| 188 | { | 177 | { |
| 189 | // look for the method | 178 | return m_direction.choose( |
| 190 | MethodMapping methodMapping = m_direction.choose( | 179 | methodMapping.getDeobfName(), |
| 191 | classMapping.getMethodByObf( in.getName(), in.getSignature() ), | 180 | methodMapping.getObfName() |
| 192 | classMapping.getMethodByDeobf( in.getName(), translateSignature( in.getSignature() ) ) | ||
| 193 | ); | 181 | ); |
| 194 | if( methodMapping != null ) | ||
| 195 | { | ||
| 196 | return m_direction.choose( | ||
| 197 | methodMapping.getDeobfName(), | ||
| 198 | methodMapping.getObfName() | ||
| 199 | ); | ||
| 200 | } | ||
| 201 | } | 182 | } |
| 202 | } | 183 | } |
| 203 | |||
| 204 | return null; | 184 | return null; |
| 205 | } | 185 | } |
| 206 | 186 | ||
| @@ -248,27 +228,23 @@ public class Translator | |||
| 248 | 228 | ||
| 249 | public String translate( ArgumentEntry in ) | 229 | public String translate( ArgumentEntry in ) |
| 250 | { | 230 | { |
| 251 | for( String className : getSelfAndAncestors( in.getClassName() ) ) | 231 | // look for the class |
| 232 | ClassMapping classMapping = findClassMapping( in.getClassEntry() ); | ||
| 233 | if( classMapping != null ) | ||
| 252 | { | 234 | { |
| 253 | // look for the class | 235 | // look for the method |
| 254 | ClassMapping classMapping = findClassMapping( new ClassEntry( className ) ); | 236 | MethodMapping methodMapping = m_direction.choose( |
| 255 | if( classMapping != null ) | 237 | classMapping.getMethodByObf( in.getMethodName(), in.getMethodSignature() ), |
| 238 | classMapping.getMethodByDeobf( in.getMethodName(), translateSignature( in.getMethodSignature() ) ) | ||
| 239 | ); | ||
| 240 | if( methodMapping != null ) | ||
| 256 | { | 241 | { |
| 257 | // look for the method | 242 | return m_direction.choose( |
| 258 | MethodMapping methodMapping = m_direction.choose( | 243 | methodMapping.getDeobfArgumentName( in.getIndex() ), |
| 259 | classMapping.getMethodByObf( in.getMethodName(), in.getMethodSignature() ), | 244 | methodMapping.getObfArgumentName( in.getIndex() ) |
| 260 | classMapping.getMethodByDeobf( in.getMethodName(), translateSignature( in.getMethodSignature() ) ) | ||
| 261 | ); | 245 | ); |
| 262 | if( methodMapping != null ) | ||
| 263 | { | ||
| 264 | return m_direction.choose( | ||
| 265 | methodMapping.getDeobfArgumentName( in.getIndex() ), | ||
| 266 | methodMapping.getObfArgumentName( in.getIndex() ) | ||
| 267 | ); | ||
| 268 | } | ||
| 269 | } | 246 | } |
| 270 | } | 247 | } |
| 271 | |||
| 272 | return null; | 248 | return null; |
| 273 | } | 249 | } |
| 274 | 250 | ||
| @@ -303,14 +279,6 @@ public class Translator | |||
| 303 | } ); | 279 | } ); |
| 304 | } | 280 | } |
| 305 | 281 | ||
| 306 | private List<String> getSelfAndAncestors( String className ) | ||
| 307 | { | ||
| 308 | List<String> ancestry = new ArrayList<String>(); | ||
| 309 | ancestry.add( className ); | ||
| 310 | ancestry.addAll( m_index.getAncestry( className ) ); | ||
| 311 | return ancestry; | ||
| 312 | } | ||
| 313 | |||
| 314 | private ClassMapping findClassMapping( ClassEntry classEntry ) | 282 | private ClassMapping findClassMapping( ClassEntry classEntry ) |
| 315 | { | 283 | { |
| 316 | ClassMapping classMapping = m_classes.get( classEntry.getOuterClassName() ); | 284 | ClassMapping classMapping = m_classes.get( classEntry.getOuterClassName() ); |
| @@ -318,7 +286,7 @@ public class Translator | |||
| 318 | { | 286 | { |
| 319 | classMapping = m_direction.choose( | 287 | classMapping = m_direction.choose( |
| 320 | classMapping.getInnerClassByObf( classEntry.getInnerClassName() ), | 288 | classMapping.getInnerClassByObf( classEntry.getInnerClassName() ), |
| 321 | classMapping.getInnerClassByDeobf( classEntry.getInnerClassName() ) | 289 | classMapping.getInnerClassByDeobfThenObf( classEntry.getInnerClassName() ) |
| 322 | ); | 290 | ); |
| 323 | } | 291 | } |
| 324 | return classMapping; | 292 | return classMapping; |