diff options
Diffstat (limited to 'src/cuchaz/enigma/mapping/Translator.java')
| -rw-r--r-- | src/cuchaz/enigma/mapping/Translator.java | 57 |
1 files changed, 36 insertions, 21 deletions
diff --git a/src/cuchaz/enigma/mapping/Translator.java b/src/cuchaz/enigma/mapping/Translator.java index d8d9f48..a5a3e2f 100644 --- a/src/cuchaz/enigma/mapping/Translator.java +++ b/src/cuchaz/enigma/mapping/Translator.java | |||
| @@ -14,21 +14,24 @@ import java.util.Map; | |||
| 14 | 14 | ||
| 15 | import com.google.common.collect.Maps; | 15 | import com.google.common.collect.Maps; |
| 16 | 16 | ||
| 17 | import cuchaz.enigma.analysis.TranslationIndex; | ||
| 17 | import cuchaz.enigma.mapping.SignatureUpdater.ClassNameUpdater; | 18 | import cuchaz.enigma.mapping.SignatureUpdater.ClassNameUpdater; |
| 18 | 19 | ||
| 19 | public class Translator { | 20 | public class Translator { |
| 20 | 21 | ||
| 21 | private TranslationDirection m_direction; | 22 | private TranslationDirection m_direction; |
| 22 | private Map<String,ClassMapping> m_classes; | 23 | private Map<String,ClassMapping> m_classes; |
| 24 | private TranslationIndex m_index; | ||
| 23 | 25 | ||
| 24 | public Translator() { | 26 | public Translator() { |
| 25 | m_direction = null; | 27 | m_direction = null; |
| 26 | m_classes = Maps.newHashMap(); | 28 | m_classes = Maps.newHashMap(); |
| 27 | } | 29 | } |
| 28 | 30 | ||
| 29 | public Translator(TranslationDirection direction, Map<String,ClassMapping> classes) { | 31 | public Translator(TranslationDirection direction, Map<String,ClassMapping> classes, TranslationIndex index) { |
| 30 | m_direction = direction; | 32 | m_direction = direction; |
| 31 | m_classes = classes; | 33 | m_classes = classes; |
| 34 | m_index = index; | ||
| 32 | } | 35 | } |
| 33 | 36 | ||
| 34 | @SuppressWarnings("unchecked") | 37 | @SuppressWarnings("unchecked") |
| @@ -100,17 +103,22 @@ public class Translator { | |||
| 100 | 103 | ||
| 101 | public String translate(FieldEntry in) { | 104 | public String translate(FieldEntry in) { |
| 102 | 105 | ||
| 103 | // look for the class | 106 | // resolve the class entry |
| 104 | ClassMapping classMapping = findClassMapping(in.getClassEntry()); | 107 | ClassEntry resolvedClassEntry = m_index.resolveEntryClass(in); |
| 105 | if (classMapping != null) { | 108 | if (resolvedClassEntry != null) { |
| 106 | 109 | ||
| 107 | // look for the field | 110 | // look for the class |
| 108 | String translatedName = m_direction.choose( | 111 | ClassMapping classMapping = findClassMapping(resolvedClassEntry); |
| 109 | classMapping.getDeobfFieldName(in.getName()), | 112 | if (classMapping != null) { |
| 110 | classMapping.getObfFieldName(in.getName()) | 113 | |
| 111 | ); | 114 | // look for the field |
| 112 | if (translatedName != null) { | 115 | String translatedName = m_direction.choose( |
| 113 | return translatedName; | 116 | classMapping.getDeobfFieldName(in.getName()), |
| 117 | classMapping.getObfFieldName(in.getName()) | ||
| 118 | ); | ||
| 119 | if (translatedName != null) { | ||
| 120 | return translatedName; | ||
| 121 | } | ||
| 114 | } | 122 | } |
| 115 | } | 123 | } |
| 116 | return null; | 124 | return null; |
| @@ -126,15 +134,22 @@ public class Translator { | |||
| 126 | 134 | ||
| 127 | public String translate(MethodEntry in) { | 135 | public String translate(MethodEntry in) { |
| 128 | 136 | ||
| 129 | // look for class | 137 | // resolve the class entry |
| 130 | ClassMapping classMapping = findClassMapping(in.getClassEntry()); | 138 | ClassEntry resolvedClassEntry = m_index.resolveEntryClass(in); |
| 131 | if (classMapping != null) { | 139 | if (resolvedClassEntry != null) { |
| 132 | 140 | ||
| 133 | // look for the method | 141 | // look for class |
| 134 | MethodMapping methodMapping = m_direction.choose(classMapping.getMethodByObf(in.getName(), in.getSignature()), | 142 | ClassMapping classMapping = findClassMapping(resolvedClassEntry); |
| 135 | classMapping.getMethodByDeobf(in.getName(), translateSignature(in.getSignature()))); | 143 | if (classMapping != null) { |
| 136 | if (methodMapping != null) { | 144 | |
| 137 | return m_direction.choose(methodMapping.getDeobfName(), methodMapping.getObfName()); | 145 | // look for the method |
| 146 | MethodMapping methodMapping = m_direction.choose( | ||
| 147 | classMapping.getMethodByObf(in.getName(), in.getSignature()), | ||
| 148 | classMapping.getMethodByDeobf(in.getName(), translateSignature(in.getSignature())) | ||
| 149 | ); | ||
| 150 | if (methodMapping != null) { | ||
| 151 | return m_direction.choose(methodMapping.getDeobfName(), methodMapping.getObfName()); | ||
| 152 | } | ||
| 138 | } | 153 | } |
| 139 | } | 154 | } |
| 140 | return null; | 155 | return null; |