summaryrefslogtreecommitdiff
path: root/src/cuchaz/enigma/gui/MatchingGui.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/cuchaz/enigma/gui/MatchingGui.java')
-rw-r--r--src/cuchaz/enigma/gui/MatchingGui.java140
1 files changed, 140 insertions, 0 deletions
diff --git a/src/cuchaz/enigma/gui/MatchingGui.java b/src/cuchaz/enigma/gui/MatchingGui.java
new file mode 100644
index 0000000..53c767a
--- /dev/null
+++ b/src/cuchaz/enigma/gui/MatchingGui.java
@@ -0,0 +1,140 @@
1package cuchaz.enigma.gui;
2
3import cuchaz.enigma.Deobfuscator;
4import cuchaz.enigma.convert.Matches;
5
6
7public class MatchingGui {
8
9 public MatchingGui(Matches matches, Deobfuscator sourceDeobfuscator, Deobfuscator destDeobfuscator) {
10 // TODO Auto-generated constructor stub
11 }
12
13
14 /* TODO: see if we can use any of this here
15 public static doTheThings() {
16
17 // get all the obf class names used in the mappings
18 Set<ClassEntry> usedClasses = Sets.newHashSet();
19 for (String className : mappings.getAllObfClassNames()) {
20 usedClasses.add(new ClassEntry(className));
21 }
22 System.out.println(String.format("Mappings reference %d/%d classes",
23 usedClasses.size(), sourceIndex.getObfClassEntries().size()
24 ));
25
26 // get the used matches
27 Collection<ClassMatch> matches = matching.matches();
28 Matches usedMatches = new Matches();
29 for (ClassMatch match : matching.matches()) {
30 if (!match.intersectSourceClasses(usedClasses).isEmpty()) {
31 usedMatches.add(match);
32 }
33 }
34 System.out.println(String.format("Mappings reference %d/%d match groups",
35 usedMatches.size(), matches.size()
36 ));
37
38 // see what the used classes map to
39 BiMap<ClassEntry,ClassEntry> uniqueUsedMatches = HashBiMap.create();
40 Map<ClassEntry,ClassMatch> ambiguousUsedMatches = Maps.newHashMap();
41 Set<ClassEntry> unmatchedUsedClasses = Sets.newHashSet();
42 for (ClassMatch match : matching.matches()) {
43 Set<ClassEntry> matchUsedClasses = match.intersectSourceClasses(usedClasses);
44 if (matchUsedClasses.isEmpty()) {
45 continue;
46 }
47
48 usedMatches.add(match);
49
50 // classify the match
51 if (!match.isMatched()) {
52 // unmatched
53 unmatchedUsedClasses.addAll(matchUsedClasses);
54 } else {
55 if (match.isAmbiguous()) {
56 // ambiguously matched
57 for (ClassEntry matchUsedClass : matchUsedClasses) {
58 ambiguousUsedMatches.put(matchUsedClass, match);
59 }
60 } else {
61 // uniquely matched
62 uniqueUsedMatches.put(match.getUniqueSource(), match.getUniqueDest());
63 }
64 }
65 }
66
67 // get unmatched dest classes
68 Set<ClassEntry> unmatchedDestClasses = Sets.newHashSet();
69 for (ClassMatch match : matching.matches()) {
70 if (!match.isMatched()) {
71 unmatchedDestClasses.addAll(match.destClasses);
72 }
73 }
74
75 // warn about the ambiguous used matches
76 if (ambiguousUsedMatches.size() > 0) {
77 System.out.println(String.format("%d source classes have ambiguous mappings", ambiguousUsedMatches.size()));
78 List<ClassMatch> ambiguousMatchesList = Lists.newArrayList(Sets.newHashSet(ambiguousUsedMatches.values()));
79 Collections.sort(ambiguousMatchesList, new Comparator<ClassMatch>() {
80 @Override
81 public int compare(ClassMatch a, ClassMatch b) {
82 String aName = a.sourceClasses.iterator().next().getName();
83 String bName = b.sourceClasses.iterator().next().getName();
84 return aName.compareTo(bName);
85 }
86 });
87 for (ClassMatch match : ambiguousMatchesList) {
88 System.out.println("Ambiguous matching:");
89 System.out.println("\tSource: " + getClassNames(match.sourceClasses));
90 System.out.println("\tDest: " + getClassNames(match.destClasses));
91 }
92 }
93
94 // warn about unmatched used classes
95 for (ClassEntry unmatchedUsedClass : unmatchedUsedClasses) {
96 System.out.println("No exact match for source class " + unmatchedUsedClass.getClassEntry());
97
98 // rank all the unmatched dest classes against the used class
99 ClassIdentity sourceIdentity = matching.getSourceIdentifier().identify(unmatchedUsedClass);
100 Multimap<Integer,ClassEntry> scoredDestClasses = ArrayListMultimap.create();
101 for (ClassEntry unmatchedDestClass : unmatchedDestClasses) {
102 ClassIdentity destIdentity = matching.getDestIdentifier().identify(unmatchedDestClass);
103 scoredDestClasses.put(sourceIdentity.getMatchScore(destIdentity), unmatchedDestClass);
104 }
105
106 List<Integer> scores = new ArrayList<Integer>(scoredDestClasses.keySet());
107 Collections.sort(scores, Collections.reverseOrder());
108 printScoredMatches(sourceIdentity.getMaxMatchScore(), scores, scoredDestClasses);
109 }
110
111 // bail if there were unmatched classes
112 if (!unmatchedUsedClasses.isEmpty()) {
113 throw new Error("There were " + unmatchedUsedClasses.size() + " unmatched classes!");
114 }
115 }
116
117 private static void printScoredMatches(int maxScore, List<Integer> scores, Multimap<Integer,ClassEntry> scoredMatches) {
118 int numScoredMatchesShown = 0;
119 for (int score : scores) {
120 for (ClassEntry classEntry : scoredMatches.get(score)) {
121 System.out.println(String.format("\tScore: %3d %3.0f%% %s",
122 score, 100.0 * score / maxScore, classEntry.getName()
123 ));
124 if (numScoredMatchesShown++ > 10) {
125 return;
126 }
127 }
128 }
129 }
130
131 private static List<String> getClassNames(Collection<ClassEntry> classes) {
132 List<String> out = Lists.newArrayList();
133 for (ClassEntry c : classes) {
134 out.add(c.getName());
135 }
136 Collections.sort(out);
137 return out;
138 }
139 */
140}