From 4be005617b3b8c3578cca07c5d085d12916f0d1d Mon Sep 17 00:00:00 2001
From: lclc98
Date: Thu, 30 Jun 2016 00:49:21 +1000
Subject: Json format (#2)
* Added new format
* Fixed bug
* Updated Version
---
.../enigma/analysis/RelatedMethodChecker.java | 104 +++++++++++++++++++++
1 file changed, 104 insertions(+)
create mode 100644 src/main/java/cuchaz/enigma/analysis/RelatedMethodChecker.java
(limited to 'src/main/java/cuchaz/enigma/analysis/RelatedMethodChecker.java')
diff --git a/src/main/java/cuchaz/enigma/analysis/RelatedMethodChecker.java b/src/main/java/cuchaz/enigma/analysis/RelatedMethodChecker.java
new file mode 100644
index 0000000..08e2dbf
--- /dev/null
+++ b/src/main/java/cuchaz/enigma/analysis/RelatedMethodChecker.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Jeff Martin.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the GNU Lesser General Public
+ * License v3.0 which accompanies this distribution, and is available at
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * Contributors:
+ * Jeff Martin - initial API and implementation
+ ******************************************************************************/
+package cuchaz.enigma.analysis;
+
+import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
+
+import java.util.Map;
+import java.util.Set;
+
+import cuchaz.enigma.mapping.*;
+
+public class RelatedMethodChecker {
+
+ private JarIndex m_jarIndex;
+ private Map, String> m_deobfNamesByGroup;
+ private Map m_deobfNamesByObfMethod;
+ private Map> m_groupsByObfMethod;
+ private Set> m_inconsistentGroups;
+
+ public RelatedMethodChecker(JarIndex jarIndex) {
+ m_jarIndex = jarIndex;
+ m_deobfNamesByGroup = Maps.newHashMap();
+ m_deobfNamesByObfMethod = Maps.newHashMap();
+ m_groupsByObfMethod = Maps.newHashMap();
+ m_inconsistentGroups = Sets.newHashSet();
+ }
+
+ public void checkMethod(ClassEntry classEntry, MethodMapping methodMapping) {
+
+ // TEMP: disable the expensive check for now, maybe we can optimize it later, or just use it for debugging
+ if (true) {
+ return;
+ }
+
+ BehaviorEntry obfBehaviorEntry = EntryFactory.getObfBehaviorEntry(classEntry, methodMapping);
+ if (!(obfBehaviorEntry instanceof MethodEntry)) {
+ // only methods have related implementations
+ return;
+ }
+ MethodEntry obfMethodEntry = (MethodEntry) obfBehaviorEntry;
+ String deobfName = methodMapping.getDeobfName();
+ m_deobfNamesByObfMethod.put(obfMethodEntry, deobfName);
+
+ // have we seen this method's group before?
+ Set group = m_groupsByObfMethod.get(obfMethodEntry);
+ if (group == null) {
+
+ // no, compute the group and save the name
+ group = m_jarIndex.getRelatedMethodImplementations(obfMethodEntry);
+ m_deobfNamesByGroup.put(group, deobfName);
+
+ assert (group.contains(obfMethodEntry));
+ for (MethodEntry relatedMethodEntry : group) {
+ m_groupsByObfMethod.put(relatedMethodEntry, group);
+ }
+ }
+
+ // check the name
+ if (!sameName(m_deobfNamesByGroup.get(group), deobfName)) {
+ m_inconsistentGroups.add(group);
+ }
+ }
+
+ private boolean sameName(String a, String b) {
+ if (a == null && b == null) {
+ return true;
+ } else if (a != null && b != null) {
+ return a.equals(b);
+ }
+ return false;
+ }
+
+ public boolean hasProblems() {
+ return m_inconsistentGroups.size() > 0;
+ }
+
+ public String getReport() {
+ StringBuilder buf = new StringBuilder();
+ buf.append(m_inconsistentGroups.size());
+ buf.append(" groups of methods related by inheritance and/or interfaces have different deobf names!\n");
+ for (Set group : m_inconsistentGroups) {
+ buf.append("\tGroup with ");
+ buf.append(group.size());
+ buf.append(" methods:\n");
+ for (MethodEntry methodEntry : group) {
+ buf.append("\t\t");
+ buf.append(methodEntry.toString());
+ buf.append(" => ");
+ buf.append(m_deobfNamesByObfMethod.get(methodEntry));
+ buf.append("\n");
+ }
+ }
+ return buf.toString();
+ }
+}
--
cgit v1.2.3