diff options
| author | 2015-03-02 01:01:51 -0500 | |
|---|---|---|
| committer | 2015-03-02 01:01:51 -0500 | |
| commit | 54d17da93c6708e54c296d63783a60f1c024797b (patch) | |
| tree | cf42c12c0956786256ff06bbb43c947addc2a573 /src/cuchaz/enigma/convert/MappingsConverter.java | |
| parent | refactor converter a bit for upcoming convert gui (diff) | |
| download | enigma-fork-54d17da93c6708e54c296d63783a60f1c024797b.tar.gz enigma-fork-54d17da93c6708e54c296d63783a60f1c024797b.tar.xz enigma-fork-54d17da93c6708e54c296d63783a60f1c024797b.zip | |
finished most of the matching gui
Diffstat (limited to 'src/cuchaz/enigma/convert/MappingsConverter.java')
| -rw-r--r-- | src/cuchaz/enigma/convert/MappingsConverter.java | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/convert/MappingsConverter.java b/src/cuchaz/enigma/convert/MappingsConverter.java index d0f9382..aa067d4 100644 --- a/src/cuchaz/enigma/convert/MappingsConverter.java +++ b/src/cuchaz/enigma/convert/MappingsConverter.java | |||
| @@ -11,17 +11,25 @@ | |||
| 11 | package cuchaz.enigma.convert; | 11 | package cuchaz.enigma.convert; |
| 12 | 12 | ||
| 13 | import java.util.Arrays; | 13 | import java.util.Arrays; |
| 14 | import java.util.Collections; | ||
| 14 | import java.util.Iterator; | 15 | import java.util.Iterator; |
| 15 | import java.util.LinkedHashMap; | 16 | import java.util.LinkedHashMap; |
| 17 | import java.util.List; | ||
| 16 | import java.util.Map; | 18 | import java.util.Map; |
| 19 | import java.util.Map.Entry; | ||
| 17 | import java.util.jar.JarFile; | 20 | import java.util.jar.JarFile; |
| 18 | 21 | ||
| 22 | import com.beust.jcommander.internal.Lists; | ||
| 19 | import com.google.common.collect.BiMap; | 23 | import com.google.common.collect.BiMap; |
| 24 | import com.google.common.collect.HashMultimap; | ||
| 20 | import com.google.common.collect.Maps; | 25 | import com.google.common.collect.Maps; |
| 26 | import com.google.common.collect.Multimap; | ||
| 21 | 27 | ||
| 28 | import cuchaz.enigma.Deobfuscator; | ||
| 22 | import cuchaz.enigma.analysis.JarIndex; | 29 | import cuchaz.enigma.analysis.JarIndex; |
| 23 | import cuchaz.enigma.convert.ClassNamer.SidedClassNamer; | 30 | import cuchaz.enigma.convert.ClassNamer.SidedClassNamer; |
| 24 | import cuchaz.enigma.mapping.ClassEntry; | 31 | import cuchaz.enigma.mapping.ClassEntry; |
| 32 | import cuchaz.enigma.mapping.ClassMapping; | ||
| 25 | import cuchaz.enigma.mapping.Mappings; | 33 | import cuchaz.enigma.mapping.Mappings; |
| 26 | 34 | ||
| 27 | public class MappingsConverter { | 35 | public class MappingsConverter { |
| @@ -100,6 +108,59 @@ public class MappingsConverter { | |||
| 100 | return lastMatching; | 108 | return lastMatching; |
| 101 | } | 109 | } |
| 102 | 110 | ||
| 111 | public static Mappings newMappings(Matches matches, Mappings oldMappings, Deobfuscator sourceDeobfuscator, Deobfuscator destDeobfuscator) { | ||
| 112 | |||
| 113 | // sort the unique matches by size of inner class chain | ||
| 114 | Multimap<Integer,Entry<ClassEntry,ClassEntry>> matchesByDestChainSize = HashMultimap.create(); | ||
| 115 | for (Entry<ClassEntry,ClassEntry> match : matches.getUniqueMatches().entrySet()) { | ||
| 116 | int chainSize = destDeobfuscator.getJarIndex().getObfClassChain(match.getValue()).size(); | ||
| 117 | matchesByDestChainSize.put(chainSize, match); | ||
| 118 | } | ||
| 119 | |||
| 120 | // build the mappings (in order of small-to-large inner chains) | ||
| 121 | Mappings newMappings = new Mappings(); | ||
| 122 | List<Integer> chainSizes = Lists.newArrayList(matchesByDestChainSize.keySet()); | ||
| 123 | Collections.sort(chainSizes); | ||
| 124 | for (int chainSize : chainSizes) { | ||
| 125 | for (Entry<ClassEntry,ClassEntry> match : matchesByDestChainSize.get(chainSize)) { | ||
| 126 | |||
| 127 | // get class info | ||
| 128 | ClassEntry sourceClassEntry = match.getKey(); | ||
| 129 | ClassEntry deobfClassEntry = sourceDeobfuscator.deobfuscateEntry(sourceClassEntry); | ||
| 130 | ClassEntry destClassEntry = match.getValue(); | ||
| 131 | List<ClassEntry> destClassChain = destDeobfuscator.getJarIndex().getObfClassChain(destClassEntry); | ||
| 132 | |||
| 133 | // find out where to make the dest class mapping | ||
| 134 | if (destClassChain.size() == 1) { | ||
| 135 | // not an inner class, add directly to mappings | ||
| 136 | newMappings.addClassMapping(new ClassMapping(destClassEntry.getName(), deobfClassEntry.getName())); | ||
| 137 | } else { | ||
| 138 | // inner class, find the outer class mapping | ||
| 139 | ClassMapping destMapping = null; | ||
| 140 | for (int i=0; i<destClassChain.size()-1; i++) { | ||
| 141 | ClassEntry destChainClassEntry = destClassChain.get(i); | ||
| 142 | if (destMapping == null) { | ||
| 143 | destMapping = newMappings.getClassByObf(destChainClassEntry); | ||
| 144 | if (destMapping == null) { | ||
| 145 | destMapping = new ClassMapping(destChainClassEntry.getName()); | ||
| 146 | newMappings.addClassMapping(destMapping); | ||
| 147 | } | ||
| 148 | } else { | ||
| 149 | destMapping = destMapping.getInnerClassByObf(destChainClassEntry.getInnerClassName()); | ||
| 150 | if (destMapping == null) { | ||
| 151 | destMapping = new ClassMapping(destChainClassEntry.getName()); | ||
| 152 | destMapping.addInnerClassMapping(destMapping); | ||
| 153 | } | ||
| 154 | } | ||
| 155 | } | ||
| 156 | String deobfName = deobfClassEntry.isInnerClass() ? deobfClassEntry.getInnerClassName() : deobfClassEntry.getSimpleName(); | ||
| 157 | destMapping.addInnerClassMapping(new ClassMapping(destClassEntry.getName(), deobfName)); | ||
| 158 | } | ||
| 159 | } | ||
| 160 | } | ||
| 161 | return newMappings; | ||
| 162 | } | ||
| 163 | |||
| 103 | public static void convertMappings(Mappings mappings, BiMap<ClassEntry,ClassEntry> changes) { | 164 | public static void convertMappings(Mappings mappings, BiMap<ClassEntry,ClassEntry> changes) { |
| 104 | 165 | ||
| 105 | // sort the changes so classes are renamed in the correct order | 166 | // sort the changes so classes are renamed in the correct order |