diff options
| author | 2016-07-04 18:14:22 +1000 | |
|---|---|---|
| committer | 2016-07-04 18:14:22 +1000 | |
| commit | 59e189bef2b5e6d129fb7c2c988ed0b2130e36ac (patch) | |
| tree | 2b638e60905251de85a4917152d6fc39a4112194 /src/main/java/cuchaz/enigma/analysis/TranslationIndex.java | |
| parent | Fixed Obf Class list order (diff) | |
| download | enigma-fork-59e189bef2b5e6d129fb7c2c988ed0b2130e36ac.tar.gz enigma-fork-59e189bef2b5e6d129fb7c2c988ed0b2130e36ac.tar.xz enigma-fork-59e189bef2b5e6d129fb7c2c988ed0b2130e36ac.zip | |
Reformat
Diffstat (limited to 'src/main/java/cuchaz/enigma/analysis/TranslationIndex.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/analysis/TranslationIndex.java | 41 |
1 files changed, 5 insertions, 36 deletions
diff --git a/src/main/java/cuchaz/enigma/analysis/TranslationIndex.java b/src/main/java/cuchaz/enigma/analysis/TranslationIndex.java index 3d8f556..275f56c 100644 --- a/src/main/java/cuchaz/enigma/analysis/TranslationIndex.java +++ b/src/main/java/cuchaz/enigma/analysis/TranslationIndex.java | |||
| @@ -15,10 +15,10 @@ import com.google.common.collect.Lists; | |||
| 15 | import com.google.common.collect.Maps; | 15 | import com.google.common.collect.Maps; |
| 16 | import com.google.common.collect.Multimap; | 16 | import com.google.common.collect.Multimap; |
| 17 | 17 | ||
| 18 | import java.io.*; | 18 | import java.util.Collection; |
| 19 | import java.util.*; | 19 | import java.util.List; |
| 20 | import java.util.zip.GZIPInputStream; | 20 | import java.util.Map; |
| 21 | import java.util.zip.GZIPOutputStream; | 21 | import java.util.Set; |
| 22 | 22 | ||
| 23 | import cuchaz.enigma.mapping.*; | 23 | import cuchaz.enigma.mapping.*; |
| 24 | import javassist.CtBehavior; | 24 | import javassist.CtBehavior; |
| @@ -26,9 +26,7 @@ import javassist.CtClass; | |||
| 26 | import javassist.CtField; | 26 | import javassist.CtField; |
| 27 | import javassist.bytecode.Descriptor; | 27 | import javassist.bytecode.Descriptor; |
| 28 | 28 | ||
| 29 | public class TranslationIndex implements Serializable { | 29 | public class TranslationIndex { |
| 30 | |||
| 31 | private static final long serialVersionUID = 738687982126844179L; | ||
| 32 | 30 | ||
| 33 | private Map<ClassEntry, ClassEntry> superclasses; | 31 | private Map<ClassEntry, ClassEntry> superclasses; |
| 34 | private Multimap<ClassEntry, FieldEntry> fieldEntries; | 32 | private Multimap<ClassEntry, FieldEntry> fieldEntries; |
| @@ -43,7 +41,6 @@ public class TranslationIndex implements Serializable { | |||
| 43 | } | 41 | } |
| 44 | 42 | ||
| 45 | public TranslationIndex(TranslationIndex other, Translator translator) { | 43 | public TranslationIndex(TranslationIndex other, Translator translator) { |
| 46 | |||
| 47 | // translate the superclasses | 44 | // translate the superclasses |
| 48 | this.superclasses = Maps.newHashMap(); | 45 | this.superclasses = Maps.newHashMap(); |
| 49 | for (Map.Entry<ClassEntry, ClassEntry> mapEntry : other.superclasses.entrySet()) { | 46 | for (Map.Entry<ClassEntry, ClassEntry> mapEntry : other.superclasses.entrySet()) { |
| @@ -82,7 +79,6 @@ public class TranslationIndex implements Serializable { | |||
| 82 | } | 79 | } |
| 83 | 80 | ||
| 84 | public void indexClass(CtClass c, boolean indexMembers) { | 81 | public void indexClass(CtClass c, boolean indexMembers) { |
| 85 | |||
| 86 | ClassEntry classEntry = EntryFactory.getClassEntry(c); | 82 | ClassEntry classEntry = EntryFactory.getClassEntry(c); |
| 87 | if (isJre(classEntry)) { | 83 | if (isJre(classEntry)) { |
| 88 | return; | 84 | return; |
| @@ -139,7 +135,6 @@ public class TranslationIndex implements Serializable { | |||
| 139 | } | 135 | } |
| 140 | 136 | ||
| 141 | public List<ClassEntry> getSubclass(ClassEntry classEntry) { | 137 | public List<ClassEntry> getSubclass(ClassEntry classEntry) { |
| 142 | |||
| 143 | // linear search is fast enough for now | 138 | // linear search is fast enough for now |
| 144 | List<ClassEntry> subclasses = Lists.newArrayList(); | 139 | List<ClassEntry> subclasses = Lists.newArrayList(); |
| 145 | for (Map.Entry<ClassEntry, ClassEntry> entry : this.superclasses.entrySet()) { | 140 | for (Map.Entry<ClassEntry, ClassEntry> entry : this.superclasses.entrySet()) { |
| @@ -191,7 +186,6 @@ public class TranslationIndex implements Serializable { | |||
| 191 | } | 186 | } |
| 192 | 187 | ||
| 193 | public ClassEntry resolveEntryClass(Entry entry) { | 188 | public ClassEntry resolveEntryClass(Entry entry) { |
| 194 | |||
| 195 | if (entry instanceof ClassEntry) { | 189 | if (entry instanceof ClassEntry) { |
| 196 | return (ClassEntry) entry; | 190 | return (ClassEntry) entry; |
| 197 | } | 191 | } |
| @@ -210,7 +204,6 @@ public class TranslationIndex implements Serializable { | |||
| 210 | } | 204 | } |
| 211 | 205 | ||
| 212 | public ClassEntry resolveSuperclass(Entry entry) { | 206 | public ClassEntry resolveSuperclass(Entry entry) { |
| 213 | |||
| 214 | // this entry could refer to a method on a class where the method is not actually implemented | 207 | // this entry could refer to a method on a class where the method is not actually implemented |
| 215 | // travel up the inheritance tree to find the closest implementation | 208 | // travel up the inheritance tree to find the closest implementation |
| 216 | while (!entryExists(entry)) { | 209 | while (!entryExists(entry)) { |
| @@ -230,7 +223,6 @@ public class TranslationIndex implements Serializable { | |||
| 230 | } | 223 | } |
| 231 | 224 | ||
| 232 | public ClassEntry resolveInterface(Entry entry) { | 225 | public ClassEntry resolveInterface(Entry entry) { |
| 233 | |||
| 234 | // the interfaces for any class is a forest | 226 | // the interfaces for any class is a forest |
| 235 | // so let's look at all the trees | 227 | // so let's look at all the trees |
| 236 | for (ClassEntry interfaceEntry : this.interfaces.get(entry.getClassEntry())) { | 228 | for (ClassEntry interfaceEntry : this.interfaces.get(entry.getClassEntry())) { |
| @@ -246,27 +238,4 @@ public class TranslationIndex implements Serializable { | |||
| 246 | String packageName = classEntry.getPackageName(); | 238 | String packageName = classEntry.getPackageName(); |
| 247 | return packageName != null && (packageName.startsWith("java") || packageName.startsWith("javax")); | 239 | return packageName != null && (packageName.startsWith("java") || packageName.startsWith("javax")); |
| 248 | } | 240 | } |
| 249 | |||
| 250 | public void write(OutputStream out) | ||
| 251 | throws IOException { | ||
| 252 | GZIPOutputStream gzipout = new GZIPOutputStream(out); | ||
| 253 | ObjectOutputStream oout = new ObjectOutputStream(gzipout); | ||
| 254 | oout.writeObject(this.superclasses); | ||
| 255 | oout.writeObject(this.fieldEntries); | ||
| 256 | oout.writeObject(this.behaviorEntries); | ||
| 257 | gzipout.finish(); | ||
| 258 | } | ||
| 259 | |||
| 260 | @SuppressWarnings("unchecked") | ||
| 261 | public void read(InputStream in) | ||
| 262 | throws IOException { | ||
| 263 | try { | ||
| 264 | ObjectInputStream oin = new ObjectInputStream(new GZIPInputStream(in)); | ||
| 265 | this.superclasses = (HashMap<ClassEntry, ClassEntry>) oin.readObject(); | ||
| 266 | this.fieldEntries = (HashMultimap<ClassEntry, FieldEntry>) oin.readObject(); | ||
| 267 | this.behaviorEntries = (HashMultimap<ClassEntry, BehaviorEntry>) oin.readObject(); | ||
| 268 | } catch (ClassNotFoundException ex) { | ||
| 269 | throw new Error(ex); | ||
| 270 | } | ||
| 271 | } | ||
| 272 | } | 241 | } |