diff options
| author | 2015-02-09 22:23:45 -0500 | |
|---|---|---|
| committer | 2015-02-09 22:23:45 -0500 | |
| commit | af1041731c8c0ce1846ff7e7b6052ed7327a5dbc (patch) | |
| tree | e781b93f526a6c1ba7b6f5e14c319450199aa1df /src/cuchaz/enigma/analysis/RelatedMethodChecker.java | |
| parent | Don't automatically move mappings around. We're more interested in stability ... (diff) | |
| download | enigma-fork-af1041731c8c0ce1846ff7e7b6052ed7327a5dbc.tar.gz enigma-fork-af1041731c8c0ce1846ff7e7b6052ed7327a5dbc.tar.xz enigma-fork-af1041731c8c0ce1846ff7e7b6052ed7327a5dbc.zip | |
fix translation issues, particularly with fields
Diffstat (limited to 'src/cuchaz/enigma/analysis/RelatedMethodChecker.java')
| -rw-r--r-- | src/cuchaz/enigma/analysis/RelatedMethodChecker.java | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/analysis/RelatedMethodChecker.java b/src/cuchaz/enigma/analysis/RelatedMethodChecker.java new file mode 100644 index 0000000..5bd67a0 --- /dev/null +++ b/src/cuchaz/enigma/analysis/RelatedMethodChecker.java | |||
| @@ -0,0 +1,96 @@ | |||
| 1 | package cuchaz.enigma.analysis; | ||
| 2 | |||
| 3 | import java.util.Map; | ||
| 4 | import java.util.Set; | ||
| 5 | |||
| 6 | import com.beust.jcommander.internal.Maps; | ||
| 7 | import com.google.common.collect.Sets; | ||
| 8 | |||
| 9 | import cuchaz.enigma.mapping.BehaviorEntry; | ||
| 10 | import cuchaz.enigma.mapping.ClassEntry; | ||
| 11 | import cuchaz.enigma.mapping.EntryFactory; | ||
| 12 | import cuchaz.enigma.mapping.MethodEntry; | ||
| 13 | import cuchaz.enigma.mapping.MethodMapping; | ||
| 14 | |||
| 15 | public class RelatedMethodChecker { | ||
| 16 | |||
| 17 | private JarIndex m_jarIndex; | ||
| 18 | private Map<Set<MethodEntry>,String> m_deobfNamesByGroup; | ||
| 19 | private Map<MethodEntry,String> m_deobfNamesByObfMethod; | ||
| 20 | private Map<MethodEntry,Set<MethodEntry>> m_groupsByObfMethod; | ||
| 21 | private Set<Set<MethodEntry>> m_inconsistentGroups; | ||
| 22 | |||
| 23 | public RelatedMethodChecker(JarIndex jarIndex) { | ||
| 24 | m_jarIndex = jarIndex; | ||
| 25 | m_deobfNamesByGroup = Maps.newHashMap(); | ||
| 26 | m_deobfNamesByObfMethod = Maps.newHashMap(); | ||
| 27 | m_groupsByObfMethod = Maps.newHashMap(); | ||
| 28 | m_inconsistentGroups = Sets.newHashSet(); | ||
| 29 | } | ||
| 30 | |||
| 31 | public void checkMethod(ClassEntry classEntry, MethodMapping methodMapping) { | ||
| 32 | |||
| 33 | // TEMP: disable the expensive check for now, maybe we can optimize it later, or just use it for debugging | ||
| 34 | if (true) return; | ||
| 35 | |||
| 36 | BehaviorEntry obfBehaviorEntry = EntryFactory.getObfBehaviorEntry(classEntry, methodMapping); | ||
| 37 | if (!(obfBehaviorEntry instanceof MethodEntry)) { | ||
| 38 | // only methods have related implementations | ||
| 39 | return; | ||
| 40 | } | ||
| 41 | MethodEntry obfMethodEntry = (MethodEntry)obfBehaviorEntry; | ||
| 42 | String deobfName = methodMapping.getDeobfName(); | ||
| 43 | m_deobfNamesByObfMethod.put(obfMethodEntry, deobfName); | ||
| 44 | |||
| 45 | // have we seen this method's group before? | ||
| 46 | Set<MethodEntry> group = m_groupsByObfMethod.get(obfMethodEntry); | ||
| 47 | if (group == null) { | ||
| 48 | |||
| 49 | // no, compute the group and save the name | ||
| 50 | group = m_jarIndex.getRelatedMethodImplementations(obfMethodEntry); | ||
| 51 | m_deobfNamesByGroup.put(group, deobfName); | ||
| 52 | |||
| 53 | assert(group.contains(obfMethodEntry)); | ||
| 54 | for (MethodEntry relatedMethodEntry : group) { | ||
| 55 | m_groupsByObfMethod.put(relatedMethodEntry, group); | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 59 | // check the name | ||
| 60 | if (!sameName(m_deobfNamesByGroup.get(group), deobfName)) { | ||
| 61 | m_inconsistentGroups.add(group); | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | private boolean sameName(String a, String b) { | ||
| 66 | if (a == null && b == null) { | ||
| 67 | return true; | ||
| 68 | } else if (a != null && b != null) { | ||
| 69 | return a.equals(b); | ||
| 70 | } | ||
| 71 | return false; | ||
| 72 | } | ||
| 73 | |||
| 74 | public boolean hasProblems() { | ||
| 75 | return m_inconsistentGroups.size() > 0; | ||
| 76 | } | ||
| 77 | |||
| 78 | public String getReport() { | ||
| 79 | StringBuilder buf = new StringBuilder(); | ||
| 80 | buf.append(m_inconsistentGroups.size()); | ||
| 81 | buf.append(" groups of methods related by inheritance and/or interfaces have different deobf names!\n"); | ||
| 82 | for (Set<MethodEntry> group : m_inconsistentGroups) { | ||
| 83 | buf.append("\tGroup with "); | ||
| 84 | buf.append(group.size()); | ||
| 85 | buf.append(" methods:\n"); | ||
| 86 | for (MethodEntry methodEntry : group) { | ||
| 87 | buf.append("\t\t"); | ||
| 88 | buf.append(methodEntry.toString()); | ||
| 89 | buf.append(" => "); | ||
| 90 | buf.append(m_deobfNamesByObfMethod.get(methodEntry)); | ||
| 91 | buf.append("\n"); | ||
| 92 | } | ||
| 93 | } | ||
| 94 | return buf.toString(); | ||
| 95 | } | ||
| 96 | } | ||