diff options
| author | 2015-03-08 20:48:30 -0400 | |
|---|---|---|
| committer | 2015-03-08 20:48:30 -0400 | |
| commit | 4ceb8d490058e48df666bf7227ce020e60928be5 (patch) | |
| tree | bdfb432cd1d61dc4914b8591468193dcd7e7421c /src/cuchaz/enigma/convert/MappingsConverter.java | |
| parent | lots of small tweaks and improvements (diff) | |
| download | enigma-fork-4ceb8d490058e48df666bf7227ce020e60928be5.tar.gz enigma-fork-4ceb8d490058e48df666bf7227ce020e60928be5.tar.xz enigma-fork-4ceb8d490058e48df666bf7227ce020e60928be5.zip | |
more tweaks, improvements, and bug fixes
Diffstat (limited to 'src/cuchaz/enigma/convert/MappingsConverter.java')
| -rw-r--r-- | src/cuchaz/enigma/convert/MappingsConverter.java | 60 |
1 files changed, 53 insertions, 7 deletions
diff --git a/src/cuchaz/enigma/convert/MappingsConverter.java b/src/cuchaz/enigma/convert/MappingsConverter.java index f38723f..5883878 100644 --- a/src/cuchaz/enigma/convert/MappingsConverter.java +++ b/src/cuchaz/enigma/convert/MappingsConverter.java | |||
| @@ -30,7 +30,10 @@ import cuchaz.enigma.analysis.JarIndex; | |||
| 30 | import cuchaz.enigma.convert.ClassNamer.SidedClassNamer; | 30 | import cuchaz.enigma.convert.ClassNamer.SidedClassNamer; |
| 31 | import cuchaz.enigma.mapping.ClassEntry; | 31 | import cuchaz.enigma.mapping.ClassEntry; |
| 32 | import cuchaz.enigma.mapping.ClassMapping; | 32 | import cuchaz.enigma.mapping.ClassMapping; |
| 33 | import cuchaz.enigma.mapping.ClassNameReplacer; | ||
| 34 | import cuchaz.enigma.mapping.FieldMapping; | ||
| 33 | import cuchaz.enigma.mapping.Mappings; | 35 | import cuchaz.enigma.mapping.Mappings; |
| 36 | import cuchaz.enigma.mapping.MethodMapping; | ||
| 34 | 37 | ||
| 35 | public class MappingsConverter { | 38 | public class MappingsConverter { |
| 36 | 39 | ||
| @@ -129,15 +132,20 @@ public class MappingsConverter { | |||
| 129 | for (Entry<ClassEntry,ClassEntry> match : matchesByDestChainSize.get(chainSize)) { | 132 | for (Entry<ClassEntry,ClassEntry> match : matchesByDestChainSize.get(chainSize)) { |
| 130 | 133 | ||
| 131 | // get class info | 134 | // get class info |
| 132 | ClassEntry sourceClassEntry = match.getKey(); | 135 | ClassEntry obfSourceClassEntry = match.getKey(); |
| 133 | ClassEntry deobfClassEntry = sourceDeobfuscator.deobfuscateEntry(sourceClassEntry); | 136 | ClassEntry obfDestClassEntry = match.getValue(); |
| 134 | ClassEntry destClassEntry = match.getValue(); | 137 | List<ClassEntry> destClassChain = destDeobfuscator.getJarIndex().getObfClassChain(obfDestClassEntry); |
| 135 | List<ClassEntry> destClassChain = destDeobfuscator.getJarIndex().getObfClassChain(destClassEntry); | 138 | |
| 139 | ClassMapping sourceMapping = sourceDeobfuscator.getMappings().getClassByObf(obfSourceClassEntry); | ||
| 140 | if (sourceMapping == null) { | ||
| 141 | // if this class was never deobfuscated, don't try to match it | ||
| 142 | continue; | ||
| 143 | } | ||
| 136 | 144 | ||
| 137 | // find out where to make the dest class mapping | 145 | // find out where to make the dest class mapping |
| 138 | if (destClassChain.size() == 1) { | 146 | if (destClassChain.size() == 1) { |
| 139 | // not an inner class, add directly to mappings | 147 | // not an inner class, add directly to mappings |
| 140 | newMappings.addClassMapping(new ClassMapping(destClassEntry.getName(), deobfClassEntry.getName())); | 148 | newMappings.addClassMapping(migrateClassMapping(obfDestClassEntry, sourceMapping, matches, false)); |
| 141 | } else { | 149 | } else { |
| 142 | // inner class, find the outer class mapping | 150 | // inner class, find the outer class mapping |
| 143 | ClassMapping destMapping = null; | 151 | ClassMapping destMapping = null; |
| @@ -157,14 +165,52 @@ public class MappingsConverter { | |||
| 157 | } | 165 | } |
| 158 | } | 166 | } |
| 159 | } | 167 | } |
| 160 | String deobfName = deobfClassEntry.isInnerClass() ? deobfClassEntry.getInnerClassName() : deobfClassEntry.getSimpleName(); | 168 | destMapping.addInnerClassMapping(migrateClassMapping(obfDestClassEntry, sourceMapping, matches, true)); |
| 161 | destMapping.addInnerClassMapping(new ClassMapping(destClassEntry.getName(), deobfName)); | ||
| 162 | } | 169 | } |
| 163 | } | 170 | } |
| 164 | } | 171 | } |
| 165 | return newMappings; | 172 | return newMappings; |
| 166 | } | 173 | } |
| 167 | 174 | ||
| 175 | private static ClassMapping migrateClassMapping(ClassEntry newObfClass, ClassMapping mapping, final Matches matches, boolean useSimpleName) { | ||
| 176 | |||
| 177 | ClassNameReplacer replacer = new ClassNameReplacer() { | ||
| 178 | @Override | ||
| 179 | public String replace(String className) { | ||
| 180 | ClassEntry newClassEntry = matches.getUniqueMatches().get(new ClassEntry(className)); | ||
| 181 | if (newClassEntry != null) { | ||
| 182 | return newClassEntry.getName(); | ||
| 183 | } | ||
| 184 | return null; | ||
| 185 | } | ||
| 186 | }; | ||
| 187 | |||
| 188 | ClassMapping newMapping; | ||
| 189 | String deobfName = mapping.getDeobfName(); | ||
| 190 | if (deobfName != null) { | ||
| 191 | if (useSimpleName) { | ||
| 192 | deobfName = new ClassEntry(deobfName).getSimpleName(); | ||
| 193 | } | ||
| 194 | newMapping = new ClassMapping(newObfClass.getName(), deobfName); | ||
| 195 | } else { | ||
| 196 | newMapping = new ClassMapping(newObfClass.getName()); | ||
| 197 | } | ||
| 198 | |||
| 199 | // copy fields | ||
| 200 | for (FieldMapping fieldMapping : mapping.fields()) { | ||
| 201 | // TODO: map field obf names too... | ||
| 202 | newMapping.addFieldMapping(new FieldMapping(fieldMapping, replacer)); | ||
| 203 | } | ||
| 204 | |||
| 205 | // copy methods | ||
| 206 | for (MethodMapping methodMapping : mapping.methods()) { | ||
| 207 | // TODO: map method obf names too... | ||
| 208 | newMapping.addMethodMapping(new MethodMapping(methodMapping, replacer)); | ||
| 209 | } | ||
| 210 | |||
| 211 | return newMapping; | ||
| 212 | } | ||
| 213 | |||
| 168 | public static void convertMappings(Mappings mappings, BiMap<ClassEntry,ClassEntry> changes) { | 214 | public static void convertMappings(Mappings mappings, BiMap<ClassEntry,ClassEntry> changes) { |
| 169 | 215 | ||
| 170 | // sort the changes so classes are renamed in the correct order | 216 | // sort the changes so classes are renamed in the correct order |