diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/mapping/MappingsChecker.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/mapping/MappingsChecker.java | 155 |
1 files changed, 77 insertions, 78 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsChecker.java b/src/main/java/cuchaz/enigma/mapping/MappingsChecker.java index 6cf279d..172641b 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsChecker.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsChecker.java | |||
| @@ -8,91 +8,90 @@ | |||
| 8 | * Contributors: | 8 | * Contributors: |
| 9 | * Jeff Martin - initial API and implementation | 9 | * Jeff Martin - initial API and implementation |
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | |||
| 11 | package cuchaz.enigma.mapping; | 12 | package cuchaz.enigma.mapping; |
| 12 | 13 | ||
| 13 | import com.google.common.collect.Lists; | 14 | import com.google.common.collect.Lists; |
| 14 | import com.google.common.collect.Maps; | 15 | import com.google.common.collect.Maps; |
| 15 | |||
| 16 | import java.util.Map; | ||
| 17 | |||
| 18 | import cuchaz.enigma.analysis.JarIndex; | 16 | import cuchaz.enigma.analysis.JarIndex; |
| 19 | 17 | ||
| 18 | import java.util.Map; | ||
| 20 | 19 | ||
| 21 | public class MappingsChecker { | 20 | public class MappingsChecker { |
| 22 | 21 | ||
| 23 | private JarIndex index; | 22 | private JarIndex index; |
| 24 | private Map<ClassEntry, ClassMapping> droppedClassMappings; | 23 | private Map<ClassEntry, ClassMapping> droppedClassMappings; |
| 25 | private Map<ClassEntry, ClassMapping> droppedInnerClassMappings; | 24 | private Map<ClassEntry, ClassMapping> droppedInnerClassMappings; |
| 26 | private Map<FieldEntry, FieldMapping> droppedFieldMappings; | 25 | private Map<FieldEntry, FieldMapping> droppedFieldMappings; |
| 27 | private Map<BehaviorEntry, MethodMapping> droppedMethodMappings; | 26 | private Map<BehaviorEntry, MethodMapping> droppedMethodMappings; |
| 28 | 27 | ||
| 29 | public MappingsChecker(JarIndex index) { | 28 | public MappingsChecker(JarIndex index) { |
| 30 | this.index = index; | 29 | this.index = index; |
| 31 | this.droppedClassMappings = Maps.newHashMap(); | 30 | this.droppedClassMappings = Maps.newHashMap(); |
| 32 | this.droppedInnerClassMappings = Maps.newHashMap(); | 31 | this.droppedInnerClassMappings = Maps.newHashMap(); |
| 33 | this.droppedFieldMappings = Maps.newHashMap(); | 32 | this.droppedFieldMappings = Maps.newHashMap(); |
| 34 | this.droppedMethodMappings = Maps.newHashMap(); | 33 | this.droppedMethodMappings = Maps.newHashMap(); |
| 35 | } | 34 | } |
| 36 | 35 | ||
| 37 | public Map<ClassEntry, ClassMapping> getDroppedClassMappings() { | 36 | public Map<ClassEntry, ClassMapping> getDroppedClassMappings() { |
| 38 | return this.droppedClassMappings; | 37 | return this.droppedClassMappings; |
| 39 | } | 38 | } |
| 40 | 39 | ||
| 41 | public Map<ClassEntry, ClassMapping> getDroppedInnerClassMappings() { | 40 | public Map<ClassEntry, ClassMapping> getDroppedInnerClassMappings() { |
| 42 | return this.droppedInnerClassMappings; | 41 | return this.droppedInnerClassMappings; |
| 43 | } | 42 | } |
| 44 | 43 | ||
| 45 | public Map<FieldEntry, FieldMapping> getDroppedFieldMappings() { | 44 | public Map<FieldEntry, FieldMapping> getDroppedFieldMappings() { |
| 46 | return this.droppedFieldMappings; | 45 | return this.droppedFieldMappings; |
| 47 | } | 46 | } |
| 48 | 47 | ||
| 49 | public Map<BehaviorEntry, MethodMapping> getDroppedMethodMappings() { | 48 | public Map<BehaviorEntry, MethodMapping> getDroppedMethodMappings() { |
| 50 | return this.droppedMethodMappings; | 49 | return this.droppedMethodMappings; |
| 51 | } | 50 | } |
| 52 | 51 | ||
| 53 | public void dropBrokenMappings(Mappings mappings) { | 52 | public void dropBrokenMappings(Mappings mappings) { |
| 54 | for (ClassMapping classMapping : Lists.newArrayList(mappings.classes())) { | 53 | for (ClassMapping classMapping : Lists.newArrayList(mappings.classes())) { |
| 55 | if (!checkClassMapping(classMapping)) { | 54 | if (!checkClassMapping(classMapping)) { |
| 56 | mappings.removeClassMapping(classMapping); | 55 | mappings.removeClassMapping(classMapping); |
| 57 | this.droppedClassMappings.put(EntryFactory.getObfClassEntry(this.index, classMapping), classMapping); | 56 | this.droppedClassMappings.put(EntryFactory.getObfClassEntry(this.index, classMapping), classMapping); |
| 58 | } | 57 | } |
| 59 | } | 58 | } |
| 60 | } | 59 | } |
| 61 | 60 | ||
| 62 | private boolean checkClassMapping(ClassMapping classMapping) { | 61 | private boolean checkClassMapping(ClassMapping classMapping) { |
| 63 | 62 | ||
| 64 | // check the class | 63 | // check the class |
| 65 | ClassEntry classEntry = EntryFactory.getObfClassEntry(this.index, classMapping); | 64 | ClassEntry classEntry = EntryFactory.getObfClassEntry(this.index, classMapping); |
| 66 | if (!this.index.getObfClassEntries().contains(classEntry)) { | 65 | if (!this.index.getObfClassEntries().contains(classEntry)) { |
| 67 | return false; | 66 | return false; |
| 68 | } | 67 | } |
| 69 | 68 | ||
| 70 | // check the fields | 69 | // check the fields |
| 71 | for (FieldMapping fieldMapping : Lists.newArrayList(classMapping.fields())) { | 70 | for (FieldMapping fieldMapping : Lists.newArrayList(classMapping.fields())) { |
| 72 | FieldEntry obfFieldEntry = EntryFactory.getObfFieldEntry(classMapping, fieldMapping); | 71 | FieldEntry obfFieldEntry = EntryFactory.getObfFieldEntry(classMapping, fieldMapping); |
| 73 | if (!this.index.containsObfField(obfFieldEntry)) { | 72 | if (!this.index.containsObfField(obfFieldEntry)) { |
| 74 | classMapping.removeFieldMapping(fieldMapping); | 73 | classMapping.removeFieldMapping(fieldMapping); |
| 75 | this.droppedFieldMappings.put(obfFieldEntry, fieldMapping); | 74 | this.droppedFieldMappings.put(obfFieldEntry, fieldMapping); |
| 76 | } | 75 | } |
| 77 | } | 76 | } |
| 78 | 77 | ||
| 79 | // check methods | 78 | // check methods |
| 80 | for (MethodMapping methodMapping : Lists.newArrayList(classMapping.methods())) { | 79 | for (MethodMapping methodMapping : Lists.newArrayList(classMapping.methods())) { |
| 81 | BehaviorEntry obfBehaviorEntry = EntryFactory.getObfBehaviorEntry(classEntry, methodMapping); | 80 | BehaviorEntry obfBehaviorEntry = EntryFactory.getObfBehaviorEntry(classEntry, methodMapping); |
| 82 | if (!this.index.containsObfBehavior(obfBehaviorEntry)) { | 81 | if (!this.index.containsObfBehavior(obfBehaviorEntry)) { |
| 83 | classMapping.removeMethodMapping(methodMapping); | 82 | classMapping.removeMethodMapping(methodMapping); |
| 84 | this.droppedMethodMappings.put(obfBehaviorEntry, methodMapping); | 83 | this.droppedMethodMappings.put(obfBehaviorEntry, methodMapping); |
| 85 | } | 84 | } |
| 86 | } | 85 | } |
| 87 | 86 | ||
| 88 | // check inner classes | 87 | // check inner classes |
| 89 | for (ClassMapping innerClassMapping : Lists.newArrayList(classMapping.innerClasses())) { | 88 | for (ClassMapping innerClassMapping : Lists.newArrayList(classMapping.innerClasses())) { |
| 90 | if (!checkClassMapping(innerClassMapping)) { | 89 | if (!checkClassMapping(innerClassMapping)) { |
| 91 | classMapping.removeInnerClassMapping(innerClassMapping); | 90 | classMapping.removeInnerClassMapping(innerClassMapping); |
| 92 | this.droppedInnerClassMappings.put(EntryFactory.getObfClassEntry(this.index, innerClassMapping), innerClassMapping); | 91 | this.droppedInnerClassMappings.put(EntryFactory.getObfClassEntry(this.index, innerClassMapping), innerClassMapping); |
| 93 | } | 92 | } |
| 94 | } | 93 | } |
| 95 | 94 | ||
| 96 | return true; | 95 | return true; |
| 97 | } | 96 | } |
| 98 | } | 97 | } |