diff options
Diffstat (limited to 'src/cuchaz/enigma/mapping/MappingsChecker.java')
| -rw-r--r-- | src/cuchaz/enigma/mapping/MappingsChecker.java | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/mapping/MappingsChecker.java b/src/cuchaz/enigma/mapping/MappingsChecker.java new file mode 100644 index 0000000..b25ea3c --- /dev/null +++ b/src/cuchaz/enigma/mapping/MappingsChecker.java | |||
| @@ -0,0 +1,107 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.mapping; | ||
| 12 | |||
| 13 | import java.util.Map; | ||
| 14 | |||
| 15 | import com.google.common.collect.Lists; | ||
| 16 | import com.google.common.collect.Maps; | ||
| 17 | |||
| 18 | import cuchaz.enigma.analysis.JarIndex; | ||
| 19 | import cuchaz.enigma.analysis.RelatedMethodChecker; | ||
| 20 | |||
| 21 | |||
| 22 | public class MappingsChecker { | ||
| 23 | |||
| 24 | private JarIndex m_index; | ||
| 25 | private RelatedMethodChecker m_relatedMethodChecker; | ||
| 26 | private Map<ClassEntry,ClassMapping> m_droppedClassMappings; | ||
| 27 | private Map<ClassEntry,ClassMapping> m_droppedInnerClassMappings; | ||
| 28 | private Map<FieldEntry,FieldMapping> m_droppedFieldMappings; | ||
| 29 | private Map<BehaviorEntry,MethodMapping> m_droppedMethodMappings; | ||
| 30 | |||
| 31 | public MappingsChecker(JarIndex index) { | ||
| 32 | m_index = index; | ||
| 33 | m_relatedMethodChecker = new RelatedMethodChecker(m_index); | ||
| 34 | m_droppedClassMappings = Maps.newHashMap(); | ||
| 35 | m_droppedInnerClassMappings = Maps.newHashMap(); | ||
| 36 | m_droppedFieldMappings = Maps.newHashMap(); | ||
| 37 | m_droppedMethodMappings = Maps.newHashMap(); | ||
| 38 | } | ||
| 39 | |||
| 40 | public RelatedMethodChecker getRelatedMethodChecker() { | ||
| 41 | return m_relatedMethodChecker; | ||
| 42 | } | ||
| 43 | |||
| 44 | public Map<ClassEntry,ClassMapping> getDroppedClassMappings() { | ||
| 45 | return m_droppedClassMappings; | ||
| 46 | } | ||
| 47 | |||
| 48 | public Map<ClassEntry,ClassMapping> getDroppedInnerClassMappings() { | ||
| 49 | return m_droppedInnerClassMappings; | ||
| 50 | } | ||
| 51 | |||
| 52 | public Map<FieldEntry,FieldMapping> getDroppedFieldMappings() { | ||
| 53 | return m_droppedFieldMappings; | ||
| 54 | } | ||
| 55 | |||
| 56 | public Map<BehaviorEntry,MethodMapping> getDroppedMethodMappings() { | ||
| 57 | return m_droppedMethodMappings; | ||
| 58 | } | ||
| 59 | |||
| 60 | public void dropBrokenMappings(Mappings mappings) { | ||
| 61 | for (ClassMapping classMapping : Lists.newArrayList(mappings.classes())) { | ||
| 62 | if (!checkClassMapping(classMapping)) { | ||
| 63 | mappings.removeClassMapping(classMapping); | ||
| 64 | m_droppedClassMappings.put(EntryFactory.getObfClassEntry(m_index, classMapping), classMapping); | ||
| 65 | } | ||
| 66 | } | ||
| 67 | } | ||
| 68 | |||
| 69 | private boolean checkClassMapping(ClassMapping classMapping) { | ||
| 70 | |||
| 71 | // check the class | ||
| 72 | ClassEntry classEntry = EntryFactory.getObfClassEntry(m_index, classMapping); | ||
| 73 | if (!m_index.getObfClassEntries().contains(classEntry)) { | ||
| 74 | return false; | ||
| 75 | } | ||
| 76 | |||
| 77 | // check the fields | ||
| 78 | for (FieldMapping fieldMapping : Lists.newArrayList(classMapping.fields())) { | ||
| 79 | FieldEntry obfFieldEntry = EntryFactory.getObfFieldEntry(classMapping, fieldMapping); | ||
| 80 | if (!m_index.containsObfField(obfFieldEntry)) { | ||
| 81 | classMapping.removeFieldMapping(fieldMapping); | ||
| 82 | m_droppedFieldMappings.put(obfFieldEntry, fieldMapping); | ||
| 83 | } | ||
| 84 | } | ||
| 85 | |||
| 86 | // check methods | ||
| 87 | for (MethodMapping methodMapping : Lists.newArrayList(classMapping.methods())) { | ||
| 88 | BehaviorEntry obfBehaviorEntry = EntryFactory.getObfBehaviorEntry(classEntry, methodMapping); | ||
| 89 | if (!m_index.containsObfBehavior(obfBehaviorEntry)) { | ||
| 90 | classMapping.removeMethodMapping(methodMapping); | ||
| 91 | m_droppedMethodMappings.put(obfBehaviorEntry, methodMapping); | ||
| 92 | } | ||
| 93 | |||
| 94 | m_relatedMethodChecker.checkMethod(classEntry, methodMapping); | ||
| 95 | } | ||
| 96 | |||
| 97 | // check inner classes | ||
| 98 | for (ClassMapping innerClassMapping : Lists.newArrayList(classMapping.innerClasses())) { | ||
| 99 | if (!checkClassMapping(innerClassMapping)) { | ||
| 100 | classMapping.removeInnerClassMapping(innerClassMapping); | ||
| 101 | m_droppedInnerClassMappings.put(EntryFactory.getObfClassEntry(m_index, innerClassMapping), innerClassMapping); | ||
| 102 | } | ||
| 103 | } | ||
| 104 | |||
| 105 | return true; | ||
| 106 | } | ||
| 107 | } | ||