diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/analysis/RelatedMethodChecker.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/analysis/RelatedMethodChecker.java | 104 |
1 files changed, 0 insertions, 104 deletions
diff --git a/src/main/java/cuchaz/enigma/analysis/RelatedMethodChecker.java b/src/main/java/cuchaz/enigma/analysis/RelatedMethodChecker.java deleted file mode 100644 index 08e2dbf..0000000 --- a/src/main/java/cuchaz/enigma/analysis/RelatedMethodChecker.java +++ /dev/null | |||
| @@ -1,104 +0,0 @@ | |||
| 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 | * <p> | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.analysis; | ||
| 12 | |||
| 13 | import com.google.common.collect.Maps; | ||
| 14 | import com.google.common.collect.Sets; | ||
| 15 | |||
| 16 | import java.util.Map; | ||
| 17 | import java.util.Set; | ||
| 18 | |||
| 19 | import cuchaz.enigma.mapping.*; | ||
| 20 | |||
| 21 | public class RelatedMethodChecker { | ||
| 22 | |||
| 23 | private JarIndex m_jarIndex; | ||
| 24 | private Map<Set<MethodEntry>, String> m_deobfNamesByGroup; | ||
| 25 | private Map<MethodEntry, String> m_deobfNamesByObfMethod; | ||
| 26 | private Map<MethodEntry, Set<MethodEntry>> m_groupsByObfMethod; | ||
| 27 | private Set<Set<MethodEntry>> m_inconsistentGroups; | ||
| 28 | |||
| 29 | public RelatedMethodChecker(JarIndex jarIndex) { | ||
| 30 | m_jarIndex = jarIndex; | ||
| 31 | m_deobfNamesByGroup = Maps.newHashMap(); | ||
| 32 | m_deobfNamesByObfMethod = Maps.newHashMap(); | ||
| 33 | m_groupsByObfMethod = Maps.newHashMap(); | ||
| 34 | m_inconsistentGroups = Sets.newHashSet(); | ||
| 35 | } | ||
| 36 | |||
| 37 | public void checkMethod(ClassEntry classEntry, MethodMapping methodMapping) { | ||
| 38 | |||
| 39 | // TEMP: disable the expensive check for now, maybe we can optimize it later, or just use it for debugging | ||
| 40 | if (true) { | ||
| 41 | return; | ||
| 42 | } | ||
| 43 | |||
| 44 | BehaviorEntry obfBehaviorEntry = EntryFactory.getObfBehaviorEntry(classEntry, methodMapping); | ||
| 45 | if (!(obfBehaviorEntry instanceof MethodEntry)) { | ||
| 46 | // only methods have related implementations | ||
| 47 | return; | ||
| 48 | } | ||
| 49 | MethodEntry obfMethodEntry = (MethodEntry) obfBehaviorEntry; | ||
| 50 | String deobfName = methodMapping.getDeobfName(); | ||
| 51 | m_deobfNamesByObfMethod.put(obfMethodEntry, deobfName); | ||
| 52 | |||
| 53 | // have we seen this method's group before? | ||
| 54 | Set<MethodEntry> group = m_groupsByObfMethod.get(obfMethodEntry); | ||
| 55 | if (group == null) { | ||
| 56 | |||
| 57 | // no, compute the group and save the name | ||
| 58 | group = m_jarIndex.getRelatedMethodImplementations(obfMethodEntry); | ||
| 59 | m_deobfNamesByGroup.put(group, deobfName); | ||
| 60 | |||
| 61 | assert (group.contains(obfMethodEntry)); | ||
| 62 | for (MethodEntry relatedMethodEntry : group) { | ||
| 63 | m_groupsByObfMethod.put(relatedMethodEntry, group); | ||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | // check the name | ||
| 68 | if (!sameName(m_deobfNamesByGroup.get(group), deobfName)) { | ||
| 69 | m_inconsistentGroups.add(group); | ||
| 70 | } | ||
| 71 | } | ||
| 72 | |||
| 73 | private boolean sameName(String a, String b) { | ||
| 74 | if (a == null && b == null) { | ||
| 75 | return true; | ||
| 76 | } else if (a != null && b != null) { | ||
| 77 | return a.equals(b); | ||
| 78 | } | ||
| 79 | return false; | ||
| 80 | } | ||
| 81 | |||
| 82 | public boolean hasProblems() { | ||
| 83 | return m_inconsistentGroups.size() > 0; | ||
| 84 | } | ||
| 85 | |||
| 86 | public String getReport() { | ||
| 87 | StringBuilder buf = new StringBuilder(); | ||
| 88 | buf.append(m_inconsistentGroups.size()); | ||
| 89 | buf.append(" groups of methods related by inheritance and/or interfaces have different deobf names!\n"); | ||
| 90 | for (Set<MethodEntry> group : m_inconsistentGroups) { | ||
| 91 | buf.append("\tGroup with "); | ||
| 92 | buf.append(group.size()); | ||
| 93 | buf.append(" methods:\n"); | ||
| 94 | for (MethodEntry methodEntry : group) { | ||
| 95 | buf.append("\t\t"); | ||
| 96 | buf.append(methodEntry.toString()); | ||
| 97 | buf.append(" => "); | ||
| 98 | buf.append(m_deobfNamesByObfMethod.get(methodEntry)); | ||
| 99 | buf.append("\n"); | ||
| 100 | } | ||
| 101 | } | ||
| 102 | return buf.toString(); | ||
| 103 | } | ||
| 104 | } | ||