diff options
| author | 2015-03-09 11:03:35 -0400 | |
|---|---|---|
| committer | 2015-03-09 11:03:35 -0400 | |
| commit | 93c053803404382163d728e044d6dd49e76a5007 (patch) | |
| tree | a5e8c610185f83550d6ae5df158fe6b619ca096c /src/cuchaz/enigma/mapping/MappingsChecker.java | |
| parent | more tweaks, improvements, and bug fixes (diff) | |
| download | enigma-fork-93c053803404382163d728e044d6dd49e76a5007.tar.gz enigma-fork-93c053803404382163d728e044d6dd49e76a5007.tar.xz enigma-fork-93c053803404382163d728e044d6dd49e76a5007.zip | |
add tracking for mismatched fields/methods
Diffstat (limited to 'src/cuchaz/enigma/mapping/MappingsChecker.java')
| -rw-r--r-- | src/cuchaz/enigma/mapping/MappingsChecker.java | 97 |
1 files changed, 97 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..c5ff7a7 --- /dev/null +++ b/src/cuchaz/enigma/mapping/MappingsChecker.java | |||
| @@ -0,0 +1,97 @@ | |||
| 1 | package cuchaz.enigma.mapping; | ||
| 2 | |||
| 3 | import java.util.Map; | ||
| 4 | |||
| 5 | import com.beust.jcommander.internal.Maps; | ||
| 6 | import com.google.common.collect.Lists; | ||
| 7 | |||
| 8 | import cuchaz.enigma.analysis.JarIndex; | ||
| 9 | import cuchaz.enigma.analysis.RelatedMethodChecker; | ||
| 10 | |||
| 11 | |||
| 12 | public class MappingsChecker { | ||
| 13 | |||
| 14 | private JarIndex m_index; | ||
| 15 | private RelatedMethodChecker m_relatedMethodChecker; | ||
| 16 | private Map<ClassEntry,ClassMapping> m_droppedClassMappings; | ||
| 17 | private Map<ClassEntry,ClassMapping> m_droppedInnerClassMappings; | ||
| 18 | private Map<FieldEntry,FieldMapping> m_droppedFieldMappings; | ||
| 19 | private Map<BehaviorEntry,MethodMapping> m_droppedMethodMappings; | ||
| 20 | |||
| 21 | public MappingsChecker(JarIndex index) { | ||
| 22 | m_index = index; | ||
| 23 | m_relatedMethodChecker = new RelatedMethodChecker(m_index); | ||
| 24 | m_droppedClassMappings = Maps.newHashMap(); | ||
| 25 | m_droppedInnerClassMappings = Maps.newHashMap(); | ||
| 26 | m_droppedFieldMappings = Maps.newHashMap(); | ||
| 27 | m_droppedMethodMappings = Maps.newHashMap(); | ||
| 28 | } | ||
| 29 | |||
| 30 | public RelatedMethodChecker getRelatedMethodChecker() { | ||
| 31 | return m_relatedMethodChecker; | ||
| 32 | } | ||
| 33 | |||
| 34 | public Map<ClassEntry,ClassMapping> getDroppedClassMappings() { | ||
| 35 | return m_droppedClassMappings; | ||
| 36 | } | ||
| 37 | |||
| 38 | public Map<ClassEntry,ClassMapping> getDroppedInnerClassMappings() { | ||
| 39 | return m_droppedInnerClassMappings; | ||
| 40 | } | ||
| 41 | |||
| 42 | public Map<FieldEntry,FieldMapping> getDroppedFieldMappings() { | ||
| 43 | return m_droppedFieldMappings; | ||
| 44 | } | ||
| 45 | |||
| 46 | public Map<BehaviorEntry,MethodMapping> getDroppedMethodMappings() { | ||
| 47 | return m_droppedMethodMappings; | ||
| 48 | } | ||
| 49 | |||
| 50 | public void dropBrokenMappings(Mappings mappings) { | ||
| 51 | for (ClassMapping classMapping : Lists.newArrayList(mappings.classes())) { | ||
| 52 | if (!checkClassMapping(classMapping)) { | ||
| 53 | mappings.removeClassMapping(classMapping); | ||
| 54 | m_droppedClassMappings.put(EntryFactory.getObfClassEntry(m_index, classMapping), classMapping); | ||
| 55 | } | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | private boolean checkClassMapping(ClassMapping classMapping) { | ||
| 60 | |||
| 61 | // check the class | ||
| 62 | ClassEntry classEntry = EntryFactory.getObfClassEntry(m_index, classMapping); | ||
| 63 | if (!m_index.getObfClassEntries().contains(classEntry)) { | ||
| 64 | return false; | ||
| 65 | } | ||
| 66 | |||
| 67 | // check the fields | ||
| 68 | for (FieldMapping fieldMapping : Lists.newArrayList(classMapping.fields())) { | ||
| 69 | FieldEntry obfFieldEntry = new FieldEntry(classEntry, fieldMapping.getObfName(), fieldMapping.getObfType()); | ||
| 70 | if (!m_index.containsObfField(obfFieldEntry)) { | ||
| 71 | classMapping.removeFieldMapping(fieldMapping); | ||
| 72 | m_droppedFieldMappings.put(obfFieldEntry, fieldMapping); | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 | // check methods | ||
| 77 | for (MethodMapping methodMapping : Lists.newArrayList(classMapping.methods())) { | ||
| 78 | BehaviorEntry obfBehaviorEntry = EntryFactory.getObfBehaviorEntry(classEntry, methodMapping); | ||
| 79 | if (!m_index.containsObfBehavior(obfBehaviorEntry)) { | ||
| 80 | classMapping.removeMethodMapping(methodMapping); | ||
| 81 | m_droppedMethodMappings.put(obfBehaviorEntry, methodMapping); | ||
| 82 | } | ||
| 83 | |||
| 84 | m_relatedMethodChecker.checkMethod(classEntry, methodMapping); | ||
| 85 | } | ||
| 86 | |||
| 87 | // check inner classes | ||
| 88 | for (ClassMapping innerClassMapping : Lists.newArrayList(classMapping.innerClasses())) { | ||
| 89 | if (!checkClassMapping(innerClassMapping)) { | ||
| 90 | classMapping.removeInnerClassMapping(innerClassMapping); | ||
| 91 | m_droppedInnerClassMappings.put(EntryFactory.getObfClassEntry(m_index, innerClassMapping), innerClassMapping); | ||
| 92 | } | ||
| 93 | } | ||
| 94 | |||
| 95 | return true; | ||
| 96 | } | ||
| 97 | } | ||